Skip to content

Commit

Permalink
Merge branch 'main' into deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
CNSeniorious000 committed Jul 8, 2024
2 parents 2423752 + 98576d7 commit 09edd61
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 5 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/spelling.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: Spell Check

on: ["push", "pull_request"]

jobs:
typos:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: crate-ci/typos@master
2 changes: 1 addition & 1 deletion src/logic/tools/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


class Browser(AbstractTool):
"""Fetch an url. The only paremeter `url`. URLs on the page can be used for reference. If you want to know any realworld fact, you should search Google."""
"""Fetch an url. The only parameter `url`. URLs on the page can be used for reference. If you want to know any realworld fact, you should search Google."""

name = "fetch"

Expand Down
7 changes: 4 additions & 3 deletions src/routes/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from typing import Annotated, Literal, cast

from fastapi import APIRouter, Depends, Request
from fastapi.responses import PlainTextResponse, StreamingResponse
from fastapi.responses import PlainTextResponse
from promplate import Node
from pydantic import BaseModel, Field

Expand All @@ -13,6 +13,7 @@
from ..utils.config import env
from ..utils.http import forward_headers
from ..utils.llm import Model, find_llm, groq, openai
from ..utils.response import make_response
from .sse import non_duplicated_event_stream

run_router = APIRouter(tags=["call"])
Expand Down Expand Up @@ -72,7 +73,7 @@ async def make_stream():
print_exc(file=stderr)
yield str(e), "error"

return StreamingResponse(make_stream(), media_type="text/event-stream")
return await make_response(make_stream(), "text/event-stream")


@run_router.put(f"{env.base}/single/{{template}}")
Expand All @@ -95,4 +96,4 @@ async def make_stream():
yield cast(str, c.result).removeprefix(last)
last = c.result

return StreamingResponse(make_stream(), media_type="text/plain")
return await make_response(make_stream())
2 changes: 1 addition & 1 deletion src/templates/schema/code_interpreter.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ There is only 1 parameters:

- `code: str`: the python code to `exec()`

For example, if you want to caculate 0.409 \* 2023, you can make a call like this:
For example, if you want to calculate 0.409 \* 2023, you can make a call like this:

```json
{
Expand Down
1 change: 1 addition & 0 deletions src/utils/llm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"claude-3-sonnet-20240229",
"claude-3-opus-20240229",
"gemma-7b-it",
"gemma2-9b-it",
"llama3-8b-8192",
"llama3-70b-8192",
"llama2-70b-4096",
Expand Down
23 changes: 23 additions & 0 deletions src/utils/response.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from operator import call
from traceback import print_exc

from fastapi.responses import PlainTextResponse, StreamingResponse
from starlette.responses import AsyncContentStream


async def make_response(stream: AsyncContentStream, media_type="text/plain"):
it = aiter(stream)

try:
first_chunk = await anext(it)
except Exception as e:
print_exc()
return PlainTextResponse("\n".join(map(str, e.args)).strip(), getattr(e, "status_code", 500))

@call
async def _():
yield first_chunk
async for i in it:
yield i

return StreamingResponse(_, media_type=media_type)

0 comments on commit 09edd61

Please sign in to comment.