-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
72 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,19 @@ | ||
# cloud | ||
Annoucing Instructor Cloud | ||
# ☁️ Instructor Cloud ☁️ | ||
|
||
Introducing Instructor Cloud | ||
|
||
With Instructor Cloud, you can: | ||
|
||
- Extract models from any text with blazing speed 🚀 | ||
- Stream extracted data in real-time | ||
- Rely on the power of GPT-4* to do your job for you! 🤖 | ||
|
||
*GPT-4 not included. Accuracy not guaranteed. Use at your own risk. | ||
|
||
## Running FastAPI | ||
|
||
To run the FastAPI server, use the following command: | ||
|
||
```sh | ||
uvicorn run:app --reload | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
instructor | ||
fastapi | ||
pydantic | ||
uvicorn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from typing import List | ||
from fastapi import FastAPI | ||
from fastapi.responses import StreamingResponse | ||
from pydantic import BaseModel | ||
|
||
|
||
import instructor | ||
import openai | ||
|
||
app = FastAPI() | ||
client = instructor.from_openai(openai.OpenAI(), model="gpt-4-turbo-preview") | ||
|
||
|
||
class Property(BaseModel): | ||
name: str | ||
value: str | ||
|
||
|
||
class User(BaseModel): | ||
name: str | ||
age: int | ||
properties: List[Property] | ||
|
||
|
||
@app.post("/v1/extract_user", response_model=User) | ||
def extract_user(text: str): | ||
user = client.chat.completions.create( | ||
messages=[ | ||
{"role": "user", "content": f"Extract user from `{text}`"}, | ||
], | ||
response_model=User, | ||
) | ||
return user | ||
|
||
|
||
@app.post("/v1/extract_user_stream") | ||
def extract_user_stream(text: str): | ||
user_stream = client.chat.completions.create_partial( | ||
messages=[ | ||
{"role": "user", "content": f"Extract user from `{text}`"}, | ||
], | ||
response_model=User, | ||
) | ||
|
||
def stream(): | ||
for partial_user in user_stream: | ||
yield f"data: {partial_user.model_dump_json()}\n\n" | ||
|
||
return StreamingResponse(stream(), media_type="text/event-stream") |