Spaces:
Running
Running
FridayMaster
commited on
Commit
•
7db8691
1
Parent(s):
62681d1
Update app.py
Browse files
app.py
CHANGED
@@ -5,7 +5,6 @@ import openai
|
|
5 |
from sentence_transformers import SentenceTransformer
|
6 |
from nltk.tokenize import sent_tokenize
|
7 |
import nltk
|
8 |
-
import torch
|
9 |
|
10 |
# Download the required NLTK data
|
11 |
nltk.download('punkt')
|
@@ -91,20 +90,22 @@ def rag_response(query, k=5, max_tokens=150):
|
|
91 |
augmented_input = query + "\n" + "\n".join(relevant_chunks)
|
92 |
|
93 |
# Generate response using OpenAI API
|
94 |
-
response = openai.
|
95 |
model="gpt-3.5-turbo",
|
96 |
-
|
|
|
|
|
|
|
97 |
max_tokens=max_tokens,
|
98 |
temperature=0.7
|
99 |
)
|
100 |
-
generated_text = response.choices[0].
|
101 |
return generated_text, distances, indices
|
102 |
except Exception as e:
|
103 |
return f"An error occurred: {e}", [], []
|
104 |
|
105 |
# Gradio Interface
|
106 |
def format_output(response, distances, indices):
|
107 |
-
# Format output to include distances and indices
|
108 |
formatted_response = f"Response: {response}\n\nDistances: {distances}\n\nIndices: {indices}"
|
109 |
return formatted_response
|
110 |
|
|
|
5 |
from sentence_transformers import SentenceTransformer
|
6 |
from nltk.tokenize import sent_tokenize
|
7 |
import nltk
|
|
|
8 |
|
9 |
# Download the required NLTK data
|
10 |
nltk.download('punkt')
|
|
|
90 |
augmented_input = query + "\n" + "\n".join(relevant_chunks)
|
91 |
|
92 |
# Generate response using OpenAI API
|
93 |
+
response = openai.ChatCompletion.create(
|
94 |
model="gpt-3.5-turbo",
|
95 |
+
messages=[
|
96 |
+
{"role": "system", "content": "You are a helpful assistant."},
|
97 |
+
{"role": "user", "content": augmented_input}
|
98 |
+
],
|
99 |
max_tokens=max_tokens,
|
100 |
temperature=0.7
|
101 |
)
|
102 |
+
generated_text = response.choices[0].message['content'].strip()
|
103 |
return generated_text, distances, indices
|
104 |
except Exception as e:
|
105 |
return f"An error occurred: {e}", [], []
|
106 |
|
107 |
# Gradio Interface
|
108 |
def format_output(response, distances, indices):
|
|
|
109 |
formatted_response = f"Response: {response}\n\nDistances: {distances}\n\nIndices: {indices}"
|
110 |
return formatted_response
|
111 |
|