Skip to content

Make open ai utils file #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions openai_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from openai import OpenAI
import key_param
import os
os.environ['OPENAI_API_KEY'] = key_param.openai_api_key

client = OpenAI()

def generate_embedding(text_chunk):
response = client.embeddings.create(input=text_chunk, model="text-embedding-ada-002")
print(response) # Temporarily add this to inspect the structure
# Adjust the attribute access based on the structure you observe
embedding_vector = response.data[0].embedding
return embedding_vector


def generate_summary(text_chunk):
system = [{"role": "system", "content": "You are Summary AI."}]
user = [{"role": "user", "content": f"Summarize this briefly:\n\n{text_chunk}"}]
chat_history = [] # past user and assistant turns, for AI memory

chat_completion = client.chat.completions.create(
messages = system + chat_history + user,
model="gpt-3.5-turbo",
max_tokens=500, top_p=0.9,
)
return(chat_completion.choices[0].message.content)