Skip to content

Commit

Permalink
Minor tweaks to setup for Azure assistants to use correct API ver in …
Browse files Browse the repository at this point in the history
…example, and handle whitespace in env variable
  • Loading branch information
dividor committed Jul 14, 2024
1 parent 2b54c6f commit 9aa5b19
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
4 changes: 2 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ RECIPE_DB_CONN_STRING=postgresql://${POSTGRES_RECIPE_USER}:${POSTGRES_RECIPE_PAS
RECIPES_OPENAI_API_TYPE=<azure or openai>
RECIPES_OPENAI_API_KEY=<API Key>
RECIPES_OPENAI_API_ENDPOINT=<only for Azure, eg https://<YOUR DEPLOYMENT NAME>.openai.azure.com/>
RECIPES_OPENAI_API_VERSION=<only for Azure, eg 2024-02-15-preview>
RECIPES_OPENAI_API_VERSION=<only for Azure, eg 2024-05-01-preview >
RECIPES_MODEL=<On Opne AI model name, on Azure the deployment name you created in Azure, eg gpt-4o>
#
# Leave these as-is for quick start
Expand Down Expand Up @@ -72,7 +72,7 @@ ASSISTANTS_API_TYPE=<azure or openai>
ASSISTANTS_API_KEY=<API Key as found on the Azure OpenAI resource>
ASSISTANTS_ID=<ID of the assistant you created in OpenAI. Leave blank if you do not have one yet>
ASSISTANTS_BASE_URL=<for Azure only, eg https://<YOUR DEPLOYMENT NAME>.openai.azure.com/>
ASSISTANTS_API_VERSION=<For Azure only, eg 2024-02-15-preview>
ASSISTANTS_API_VERSION=<For Azure only, eg 2024-05-01-preview >
ASSISTANTS_MODEL=<On Open AI, the model name, on Azure the deployment name of the model you created in Azure which the assitant uses, eg gpt-4o>
ASSISTANTS_BOT_NAME=<Your assistant name, eg "Humanitarian AI Assistant">

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ This repo contains a docker-compose environment that will run the following comp
In a terminal, navigate to the repo top folder and run `docker compose exec chat python create_update_assistant.py`
Make note of the assitant ID, then edit your `.env` file and using it set variable `ASSISTANTS_ID`.
Make note of the assitant ID printed, then edit your `.env` file and using it set variable `ASSISTANTS_ID`.
Note: (i) If you rerun `create_update_assistant.py` once `ASSISTANTS_ID` is set, the script will update the assistant rather than create a new one. You will need to do this if trying different models; (ii) You can also add your own data, pdf, docx, csv, xlsx files for the assistant to use, see section 'Adding your own files for the assistant to analyze' below.
Expand Down
19 changes: 10 additions & 9 deletions assistants/chat_ui/create_update_assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def create_update_assistant():
f.write(instructions)

# Upload any local files needed by assistant for file_search (RAG)
vector_store_id = upload_files_to_vector_store("local_files_vectore_store", client)
vector_store_id = upload_files_to_vector_store("local_files_vector_store", client)

# Upload any files that will be used for code_interpretor
code_interpreter_file_ids = upload_files_for_code_interpreter(client)
Expand Down Expand Up @@ -258,23 +258,24 @@ def create_update_assistant():
if "code_interpreter" in tool_resources or "file_search" in tool_resources:
params["tool_resources"] = tool_resources

# If we were provided an ID in .env, pass it in to update existing assistant
if assistant_id is not None:
params["assistant_id"] = assistant_id

print(json.dumps(params, indent=4))
print(json.dumps(params, indent=2))

if assistant_id is None:
if (
assistant_id is None
or assistant_id == ""
or assistant_id.replace(" ", "") == ""
):
print(
f"Calling assistant API for ID: {assistant_id}, name: {bot_name} and model {model} ..."
f"Calling CREATE assistant API for ID: {assistant_id}, name: {bot_name} and model {model} ..."
)
assistant = client.beta.assistants.create(**params)
print("Assistant created!! Here is the assistant ID:\n")
print(assistant.id)
print("\nNow update ASSISTANTS_ID in your .env file with this ID")
else:
params["assistant_id"] = assistant_id
print(
f"Calling assistant API for ID: {assistant_id}, name: {bot_name} and model {model} ..."
f"Calling UPDATE assistant API for ID: {assistant_id}, name: {bot_name} and model {model} ..."
)
assistant = client.beta.assistants.update(**params)
print("Assistant updated!!")
Expand Down

0 comments on commit 9aa5b19

Please sign in to comment.