asrafnoor commited on
Commit
d0906b5
·
verified ·
1 Parent(s): 860c276

Create main.py

Browse files
Files changed (1) hide show
  1. main.py +19 -0
main.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ import openai
3
+
4
+ app = FastAPI()
5
+
6
+ # Set up OpenAI API key
7
+ openai.api_key = "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"
8
+
9
+ @app.post("/generate")
10
+ def generate_text(prompt: str):
11
+ response = openai.Completion.create(
12
+ engine="gpt-4", # Replace with the GPT-4 engine when available
13
+ prompt=prompt,
14
+ max_tokens=1024,
15
+ temperature=0.7,
16
+ )
17
+ return response.choices[0].text
18
+
19
+ # Run the app with `uvicorn main:app --reload`