brackozi commited on
Commit
d935b4a
·
1 Parent(s): 7c548a4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -12
app.py CHANGED
@@ -7,19 +7,19 @@ openai.api_key = os.environ["OPENAI_API_KEY"]
7
 
8
  def translate_code(code, from_language, to_language):
9
  try:
10
- prompt = f"Translate the following {from_language} code to {to_language}:\n{code}\n---\nTranslated code:\n"
 
 
 
 
 
 
 
 
 
 
11
 
12
- response = openai.Completion.create(
13
- engine="gpt-3.5-turbo",
14
- prompt=prompt,
15
- max_tokens=200,
16
- n=1,
17
- stop=None,
18
- temperature=0.6,
19
- top_p=1,
20
- frequency_penalty=0,
21
- presence_penalty=0,
22
- )
23
 
24
  translated_code = response.choices[0].text.strip()
25
  return translated_code
 
7
 
8
  def translate_code(code, from_language, to_language):
9
  try:
10
+ context = f"Translate the following {from_language} code to {to_language}:\n{code}\n---\nTranslated code:\n"
11
+
12
+ data = {
13
+ "model": "gpt-3.5-turbo",
14
+ "messages": [{"role": "system", "content": "You are a helpful assistant that translates code between different programming languages."}, {"role": "user", "content": context}],
15
+ "max_tokens": 200,
16
+ "temperature": 0.6,
17
+ "top_p": 1,
18
+ "frequency_penalty": 0,
19
+ "presence_penalty": 0,
20
+ }
21
 
22
+ response = openai.ChatCompletion.create(**data)
 
 
 
 
 
 
 
 
 
 
23
 
24
  translated_code = response.choices[0].text.strip()
25
  return translated_code