From 8abc176c440499a4de8406fd58b7d2c0a4e5b9ff Mon Sep 17 00:00:00 2001 From: Nate Buttke Date: Tue, 15 Aug 2023 23:29:58 -0700 Subject: use new 3.5 turbo chat model. --- server.py | 40 ++++++++++++++++++++++++++++------------ setup.py | 35 +++++++++++++++++------------------ 2 files changed, 45 insertions(+), 30 deletions(-) diff --git a/server.py b/server.py index 1cd914c..cd27865 100644 --- a/server.py +++ b/server.py @@ -39,18 +39,34 @@ def generate_answer(question): for i in range(3): prompt += results.iloc[i]["summary"] + "\n" + results.iloc[i]["blob"] + "\n" prompt += "\n" + "Answer the following question using the code context given above, and show an example with 'Example'\nQ: " + question + "\nA: " - response = openai.Completion.create( - model="text-davinci-003", - # model="code-davinci-002", - prompt=prompt, - temperature=0.7, - max_tokens=1000, - top_p=1.0, - frequency_penalty=0.0, - presence_penalty=0.0, - stop=["\"\"\""] - ) - return response["choices"][0]["text"] + + response = openai.ChatCompletion.create( + model="gpt-3.5-turbo", + messages=[{"role": "user", "content": prompt}], + temperature=0.7, + max_tokens=300, + top_p=1.0, + frequency_penalty=0.0, + presence_penalty=0.0, + stop=["\"\"\""] + ) + resp = response["choices"][0]["message"]["content"] + + counter = 0 + outstr = "" + for char in resp: + if counter == 60: + outstr += "\n" + counter = 0 + if char == "\n": + counter = 0 + outstr += " " + else: + counter += 1 + outstr += char + + #return [response["choices"][0]["text"], ""] + return [outstr, ""] def add_to_tree(tree: dict, path: str): parts = PurePosixPath(path).parts diff --git a/setup.py b/setup.py index 9efb57c..7bbfd6d 100644 --- a/setup.py +++ b/setup.py @@ -146,21 +146,20 @@ def generate_summary(prompt): if (len(enc.encode(prompt)) > 3000): return "too long to summarize." - prompt = prompt + '\nSummarize the above code: ' - - # response = openai.ChatCompletion.create( - # model="gpt-3.5-turbo", - # messages=[{"role": "user", "content": prompt}], - # temperature=0.7, - # max_tokens=1024, - # top_p=1.0, - # frequency_penalty=0.0, - # presence_penalty=0.0, - # stop=["\"\"\""] - # ) - - #return response["choices"][0]["message"]["content"] - return 'herro. this is a test summary' + prompt = prompt + '\nSummarize the above code (be succinct): ' + + response = openai.ChatCompletion.create( + model="gpt-3.5-turbo", + messages=[{"role": "user", "content": prompt}], + temperature=0.7, + max_tokens=300, + top_p=1.0, + frequency_penalty=0.0, + presence_penalty=0.0, + stop=["\"\"\""] + ) + + return response["choices"][0]["message"]["content"] # create blob. the blob just contains the file path and the source code. def blobify(pandaSeries): @@ -234,9 +233,9 @@ def setup( print('generating embeddings') embedding_model = "text-embedding-ada-002" - #code_df["embedding_summary"] = code_df.summary.apply( - # [lambda x: get_embedding(x, engine=embedding_model)] - # ) + code_df["embedding_summary"] = code_df.summary.apply( + [lambda x: get_embedding(x, engine=embedding_model)] + ) print('done with embeddings') code_df.to_csv(output_csv_filepath) -- cgit v1.2.3