Spaces:
Sleeping
Sleeping
Update text2generation.py
Browse files- text2generation.py +12 -7
text2generation.py
CHANGED
@@ -1,14 +1,15 @@
|
|
1 |
-
from openai import OpenAI
|
2 |
import os
|
3 |
-
|
4 |
-
client = OpenAI(
|
5 |
-
base_url="https://openrouter.ai/api/v1/chat/completions",
|
6 |
-
api_key=os.getenv("OPENROUTER_API_KEY")
|
7 |
-
)
|
8 |
|
9 |
def generate_educational_content(question):
|
10 |
"""Generate all content formats for a question"""
|
11 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
# Step 1: Get detailed explanation
|
13 |
detailed_response = client.chat.completions.create(
|
14 |
model="deepseek/deepseek-chat-v3-0324:free",
|
@@ -19,7 +20,11 @@ def generate_educational_content(question):
|
|
19 |
Question: {question}"""
|
20 |
}],
|
21 |
temperature=0.7,
|
22 |
-
max_tokens=2000
|
|
|
|
|
|
|
|
|
23 |
)
|
24 |
detailed_answer = detailed_response.choices[0].message.content
|
25 |
|
|
|
|
|
1 |
import os
|
2 |
+
from openai import OpenAI
|
|
|
|
|
|
|
|
|
3 |
|
4 |
def generate_educational_content(question):
|
5 |
"""Generate all content formats for a question"""
|
6 |
try:
|
7 |
+
# Initialize client without proxies parameter
|
8 |
+
client = OpenAI(
|
9 |
+
base_url="https://openrouter.ai/api/v1",
|
10 |
+
api_key=os.getenv("OPENROUTER_API_KEY")
|
11 |
+
)
|
12 |
+
|
13 |
# Step 1: Get detailed explanation
|
14 |
detailed_response = client.chat.completions.create(
|
15 |
model="deepseek/deepseek-chat-v3-0324:free",
|
|
|
20 |
Question: {question}"""
|
21 |
}],
|
22 |
temperature=0.7,
|
23 |
+
max_tokens=2000,
|
24 |
+
headers={
|
25 |
+
"HTTP-Referer": "https://your-huggingface-space.hf.space",
|
26 |
+
"X-Title": "Educational AI Assistant"
|
27 |
+
}
|
28 |
)
|
29 |
detailed_answer = detailed_response.choices[0].message.content
|
30 |
|