Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
jxnl committed Apr 1, 2024
1 parent c8a5ff2 commit bbae49e
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 2 deletions.
21 changes: 19 additions & 2 deletions README.md
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
```
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
instructor
fastapi
pydantic
uvicorn
49 changes: 49 additions & 0 deletions run.py
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")

0 comments on commit bbae49e

Please sign in to comment.