-
Notifications
You must be signed in to change notification settings - Fork 0
/
intro-chat-prompts2.py
37 lines (32 loc) · 1.04 KB
/
intro-chat-prompts2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import os
import openai
from dotenv import find_dotenv, load_dotenv
from langchain_openai import OpenAI
from langchain_openai import ChatOpenAI
from langchain.schema import HumanMessage
load_dotenv(find_dotenv())
openai.api_key = os.getenv("OPENAI_API_KEY")
llm_model = "gpt-3.5-turbo"
chat_model = ChatOpenAI(temperature=0.7, model=llm_model)
# OpenAI Completion Endpoint
def get_completion(prompt, model=llm_model):
messages = [{"role": "user", "content": prompt}]
response = openai.ChatCompletion.create(
model=model,
messages=messages,
temperature=0,
)
return response.choices[0].message["content"]
# Translate text, review
customer_review = """
Your product is terrible! I don't knnow how
you were able to get this to market.
I don't want this! Actually no one should want this.
Seriously! Give me my money back now!
"""
prompt = """
Rewrite the customer review message in a polite tone, and then
please translate the new review message into French.
"""
rewrite =get_completion(prompt=prompt)
print(rewrite)