-
-
Notifications
You must be signed in to change notification settings - Fork 17
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some spellcheck issues
Tested it with an OpenAPI Key - { Updated code: import os
from openai import OpenAI
from nitric.resources import api
from nitric.application import Nitric
from nitric.context import HttpContext
# Configure OpenAI API key from env
api_key = os.environ.get("OPENAI_API_KEY")
if not api_key:
raise Exception("Please set the OPENAI_API_KEY environment variable")
# Create OpenAI client
client = OpenAI(api_key=api_key)
# Define Nitric API
summarize_api = api("main")
@summarize_api.post("/summarize")
async def summarize_text(ctx: HttpContext) -> None:
req_data = ctx.req.json
if not req_data or 'text' not in req_data:
ctx.res.status = 400
ctx.res.body = {"error": "No text provided for summarization."}
return
text_to_summarize = req_data['text']
try:
response = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[{"role": "user", "content": f"Summarize the following text:\n\n{text_to_summarize}"}],
max_tokens=50
)
summary = response.choices[0].message.content
ctx.res.body = {"summary": summary.strip()}
except Exception as e:
ctx.res.status = 500
ctx.res.body = {"error": str(e)}
Nitric.run() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update code to deal with deprecations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot wasn't able to review any files in this pull request.
Files not reviewed (2)
- dictionary.txt: Language not supported
- docs/guides/python/serverless-ai-api.mdx: Language not supported
4c66c42
to
908289e
Compare
Co-authored-by: Ryan Cartwright <[email protected]>
No description provided.