Skip to content

Commit

Permalink
[BUG] update openai api in example (#1641)
Browse files Browse the repository at this point in the history
## Description of changes
- Update openai call to use the new api (#1640 )
  • Loading branch information
nicolasgere authored Jan 17, 2024
1 parent 22da192 commit d49ec77
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions examples/chat_with_your_documents/main.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import argparse
import os
from typing import List, Dict

from openai.types.chat import ChatCompletionMessageParam
import openai
import chromadb


def build_prompt(query: str, context: List[str]) -> List[Dict[str, str]]:
def build_prompt(query: str, context: List[str]) -> List[ChatCompletionMessageParam]:
"""
Builds a prompt for the LLM. #
Expand All @@ -21,22 +21,22 @@ def build_prompt(query: str, context: List[str]) -> List[Dict[str, str]]:
context (List[str]): The context of the query, returned by embedding search.
Returns:
A prompt for the LLM (List[Dict[str, str]]).
A prompt for the LLM (List[ChatCompletionMessageParam]).
"""

system = {
system: ChatCompletionMessageParam = {
"role": "system",
"content": "I am going to ask you a question, which I would like you to answer"
"based only on the provided context, and not any other information."
"If there is not enough information in the context to answer the question,"
'say "I am not sure", then try to make a guess.'
"Break your answer up into nicely readable paragraphs.",
}
user = {
user: ChatCompletionMessageParam = {
"role": "user",
"content": f"The question is {query}. Here is all the context you have:"
f'{(" ").join(context)}',
}
}

return [system, user]

Expand All @@ -52,7 +52,7 @@ def get_chatGPT_response(query: str, context: List[str], model_name: str) -> str
Returns:
A response to the question.
"""
response = openai.ChatCompletion.create(
response = openai.chat.completions.create(
model=model_name,
messages=build_prompt(query, context),
)
Expand Down
2 changes: 1 addition & 1 deletion examples/chat_with_your_documents/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
chromadb>=0.4.4
openai
openai>=1.7.2
tqdm

0 comments on commit d49ec77

Please sign in to comment.