#I am trying to figure out how to pass extensive knowledge via an API to my python assistant, which w

1 messages · Page 1 of 1 (latest)

south wind
#

I am trying to figure out how to pass extensive knowledge via an API to my python assistant, which works via API and then does other things with Python (writes to files, Excel, documents, on WordPress).

To create the chat completion response, I use:

This is python:


openai.api_key = openai_key # Ensure openai_key is defined securely

Create the chat completion response

response = openai.ChatCompletion.create(

model='xxxxxxxxxxxx',

temperature=1,

messages=[{"role": "system", "content": "You are an expert. Whatever user asks you, you reply by writing an article about it"},

{"role": "user", "content": mainprompt}],

)

Extract the text content from the response

content = response["choices"][0]["message"]["content"]


How can I provide it with very extensive knowledge?

(Let's assume that the knowledge base I provide to the assistants or GPT is a .txt file)

Thank you very much for your answers.

distant ploverBOT
#

Hi @south wind. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

To provide your assistant with extensive knowledge, you can use the Assistants API, which allows you to upload documents that the assistant can refer to when generating responses. This is particularly useful when you want the assistant to have access to a large amount of information that is not included in the initial prompt.

Here's an example of how you can create an assistant and associate it with a file:

from openai import OpenAI
import os

client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY", "<your OpenAI API key if not set as env var>"))

assistant = client.beta.assistants.create(
 name="Assistant",
 instructions="You are a personal assistant chatbot. When asked a question, always refer to the uploaded file in order to provide the best answer.",
 model="gpt-4-1106-preview",
 tools=[{"type": "retrieval"}],
 file_ids=[file_id],  # file_id is the ID of the file you uploaded
)

In this example, file_id is the ID of the file you uploaded to OpenAI's servers. The assistant will use this file as a source of information when generating responses.

Please note that the file should be uploaded to OpenAI's servers before you can use its ID. The process of uploading a file is not covered in the provided extracts.

You can find more information about the Assistants API in the OpenAI Cookbook (https://cookbook.openai.com/examples/assistants_api_overview_python) and the OpenAI API documentation (https://platform.openai.com/docs/assistants/overview).

Remember to replace <your OpenAI API key if not set as env var> with your actual OpenAI API key. If you're using an environment variable to store the key, you can leave it as is.

#

Please note that the model gpt-4-1106-preview used in the example might not be available at the time you're implementing this. You should replace it with the model you're planning to use.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@south wind kapa.ai is still learning and improving, please let us know how it did by reacting below

south wind
#

no i am tying to do with api and python locally on my pc

south wind
signal dagger
#

你好