Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
0d47c43
gguf: add GGUFReader.read_field(field) method + read template example
Apr 27, 2024
0d1d46e
grammars: add troubleshooting section to readme
Apr 8, 2024
63d1324
server.py: hacky code
Mar 25, 2024
ffc7436
agents: scripts to run scripts as sandboxed fastapi servers
Mar 26, 2024
d5d9993
server.py: default tools work!
Mar 26, 2024
8afd4de
server.py: make tools work w/ mixtral-8x7b-instruct
Mar 27, 2024
aa9605c
server.py: kinda api-compliant output, disabled grammar
Mar 27, 2024
a406293
server.py: reenable grammar, accommodate mistral's escaped underscores
Mar 27, 2024
63a384d
server.py: raise n_predict
Mar 28, 2024
5f3de16
server.py: pass all request options, comments in ts sigs, render tool…
Mar 28, 2024
59b4114
server.py: refactor chat handlers
Mar 29, 2024
253b68d
server.py: crude reactor
Mar 29, 2024
e874565
agent: split code from openai example
Mar 29, 2024
b63f91a
Update agent.py
Mar 29, 2024
c340e8c
Update example_weather_tools.py
Mar 29, 2024
ce2fb01
agent: add --allow_parallel_calls
Mar 29, 2024
ea34bd3
agent/openai:nits
Mar 29, 2024
80c7930
openai: fix message merging for mixtral (parallel calls)
Mar 29, 2024
9ab493f
Update prompting.py
Mar 29, 2024
e0c8af4
agent: --style
Mar 29, 2024
b4e292e
Create requirements.txt
Mar 29, 2024
d1d8602
agent: disable parallel by default
Mar 29, 2024
eb9a552
agent: nits
Mar 29, 2024
3da30ed
agent: fix functionary tool_calls templating
Mar 29, 2024
ff6563a
Delete test.sh
Mar 29, 2024
dd11bb6
agent: format still broken
Mar 29, 2024
22b980f
agent: update readme
Mar 29, 2024
61f35e0
agent: prepare to test various templates
Mar 29, 2024
d8a53ea
openai: test features of templates at runtime, to make sure no bits o…
Mar 30, 2024
ad2f4c1
Update test_chat_handlers.py
Mar 30, 2024
3c3eff5
openai: quiet + update prompt output
Mar 30, 2024
6935503
openai: refactor chat handler vs. template
Mar 30, 2024
d9f30f8
Update test_chat_handlers.md
Mar 30, 2024
da2067a
openai: only special-format assistant in thoughtful mode
Mar 30, 2024
09de4eb
openai: actually use thoughtful examples in tests
Mar 30, 2024
19811a4
openai: tests didn't catch output format
Mar 30, 2024
22fe86d
openai tools: TS signatures work well too at a fraction of the eval cost
Mar 30, 2024
6e52a9c
Update test_chat_handlers.md
Apr 8, 2024
701a66d
agent: fix response_format
Apr 9, 2024
b447a74
agent: revert to json schemas (ts not ready for refs)
Apr 9, 2024
85820f4
agent: fix sandbox dockerfile
Apr 9, 2024
6880f1d
agent: support basic openapi tools (incl. from fastify sandbox)
Apr 9, 2024
0532680
agent: nits
Apr 9, 2024
a634e03
agent: cache_prompt=True
Apr 10, 2024
9fe269e
openai: nit
Apr 10, 2024
a61ebeb
agent: hint at math import in python tool
Apr 10, 2024
24e34f1
agent: nit
Apr 10, 2024
1475b1e
agent: fix killing of subprocesses
Apr 10, 2024
6c00378
agent: nits
Apr 10, 2024
082d54d
agent: rename fake weather tools
Apr 10, 2024
f9afb04
agent: python tool: test serializability of variables
Apr 10, 2024
a98f483
agent: python tool: return errors
Apr 10, 2024
ea0c31b
agent: ensure DATA_DIR exists
Apr 10, 2024
89dcc06
agent: mypy type fixes
Apr 10, 2024
0120f7c
agent: fix wait --std-tools
Apr 10, 2024
09c2565
grammars: early exit when no next_candidates to reject
Apr 21, 2024
00c709e
grammars: cache decoded tokens
Apr 21, 2024
8d503ef
grammars: faster llama_grammar_copy
Apr 21, 2024
b4a00ce
Merge branch 'gguf-read' into agent-example
Apr 27, 2024
7675ac6
Merge remote-tracking branch 'origin/master' into agent-example
Apr 30, 2024
312e20b
openai: update after merge
Apr 30, 2024
ca1a640
server: tool call grammar-constraints
May 2, 2024
2b2127c
agent: url params
May 2, 2024
e41b6ce
server: update tool calling, introduce system prompt for json schema
May 2, 2024
a1d64cf
openai: function call arguments must be returned stringified!
May 18, 2024
3f5a25f
Merge remote-tracking branch 'origin/master' into agent-example
May 18, 2024
5ea637e
openai: fix merge
May 21, 2024
6dadcd2
Merge remote-tracking branch 'origin/master' into agent-example
May 21, 2024
c8458fa
openai: make content optional for tool call grammar gen
May 22, 2024
a39e6e0
openai: pretty indent json response
May 22, 2024
793f4ff
agent: support OpenAI: --endpoint https://api.openai.com --auth "Bear…
May 22, 2024
a1c4aac
server: ultra basic tools, tool_choice, tool_calls support
May 22, 2024
298c098
Merge remote-tracking branch 'origin/master' into agent-example
Jun 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
agent/openai:nits
  • Loading branch information
ochafik committed Apr 27, 2024
commit ea34bd3e5c42f7a71cb2530e52ae8a2736cef4b8
2 changes: 1 addition & 1 deletion examples/agent/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ This example relies on the new [OpenAI compatibility server](../openai).
agent.py β†’ examples.openai β†’ server.cpp
β†’ safe_tools.py
β†’ ( run_sandboxed_tools.sh : Docker β†’ fastify.py ) β†’ unsafe_tools.py β†’ code interpreter, etc...
```
```

The agent can use tools written in Python, or (soon) exposed under OpenAPI endpoints. Only has standard Python deps (e.g. no langchain)

Expand Down
12 changes: 6 additions & 6 deletions examples/agent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def main(
max_iterations: Optional[int] = 10,
std_tools: Optional[bool] = False,
auth: Optional[str] = None,
allow_parallel_calls: Optional[bool] = False,
parallel_calls: Optional[bool] = True,
verbose: bool = False,

model: Annotated[Optional[Path], typer.Option("--model", "-m")] = "models/7B/ggml-model-f16.gguf",
Expand Down Expand Up @@ -174,14 +174,14 @@ def main(
"python", "-m", "examples.openai.server",
"--model", model,
*(['--verbose'] if verbose else []),
*(['--allow-parallel-calls'] if allow_parallel_calls else []),
*(['--parallel-calls'] if parallel_calls else []),
*(['--context-length={context_length}'] if context_length else []),
*([])
]
server_process = subprocess.Popen(cmd, stdout=sys.stderr)
atexit.register(server_process.kill)
sleep(5)

tool_functions = []
types = {}
for f in tools:
Expand All @@ -195,7 +195,7 @@ def main(

if std_tools:
tool_functions.extend(collect_functions(StandardTools))

response_model = None#str
if format:
if format in types:
Expand All @@ -207,8 +207,8 @@ def main(
response_model = json.loads(format)
except:
response_model = eval(format)


result = completion_with_tool_usage(
model="...",
endpoint=endpoint,
Expand Down
2 changes: 1 addition & 1 deletion examples/agent/fastify.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ def main(files: List[str], host: str = '0.0.0.0', port: int = 8000):

if __name__ == '__main__':
typer.run(main)

2 changes: 1 addition & 1 deletion examples/agent/run_sandboxed_tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ script="$( realpath "$1" )"
script_folder="$(dirname "$script")"
shift 1

function cleanup {
function cleanup {
rm -rf "$BUILD_DIR"
echo "Deleted $BUILD_DIR"
}
Expand Down
14 changes: 5 additions & 9 deletions examples/agent/tools/std_tools.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import atexit
from datetime import date
import datetime
from pydantic import BaseModel
import subprocess
import sys
from time import sleep
import time
import typer
from pydantic import BaseModel, Json, TypeAdapter
from annotated_types import MinLen
from typing import Annotated, Callable, List, Union, Literal, Optional, Type, get_args, get_origin
import json, requests
from typing import Union, Optional

class Duration(BaseModel):
seconds: Optional[int] = None
Expand Down Expand Up @@ -50,7 +46,7 @@ def __call__(self):
sys.stderr.write(f"Waiting for {days} days and {seconds} seconds until {d}...\n")
time.sleep(days * 86400 + seconds)
sys.stderr.write(f"Reached the target date: {self.until}\n")


class StandardTools:

Expand All @@ -61,15 +57,15 @@ def ask_user(question: str) -> str:
This allows getting additional information, requesting disambiguation, etc.
'''
return typer.prompt(question)

@staticmethod
def wait(_for: Union[WaitForDuration, WaitForDate]) -> None:
'''
Wait for a certain amount of time before continuing.
This can be used to wait for a specific duration or until a specific date.
'''
return _for()

@staticmethod
def say_out_loud(something: str) -> str:
"""
Expand Down
6 changes: 3 additions & 3 deletions examples/openai/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ The new [examples/openai/server.py](./server.py):
}
// Where T is the output JSON schema, or 'any'
```

- Option to publicise schemas to models as TypeScript signatures (as for Functionary) or JSON schema.

- Supports models that require user/assistant alternance (like Mixtral Instruct) by merging system messages into user messages.
Expand Down Expand Up @@ -175,7 +175,7 @@ curl http://localhost:8080/v1/chat/completions \
- Evaluate options for session caching

- Pass session id & store / read from file?

- Support parent session ids for trees of thought?

- Support precaching long prompts from CLI / read session files?
Expand All @@ -186,4 +186,4 @@ curl http://localhost:8080/v1/chat/completions \

- Remove non-Python json-schema-to-grammar versions

- Reach out to frameworks to advertise new option.
- Reach out to frameworks to advertise new option.
26 changes: 5 additions & 21 deletions examples/openai/llama_cpp_server_api.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,12 @@
from typing import Optional
from pydantic import BaseModel, Json
from pydantic import Json

class LlamaCppServerCompletionRequest(BaseModel):
from examples.openai.api import LlamaCppParams

class LlamaCppServerCompletionRequest(LlamaCppParams):
prompt: str
stream: Optional[bool] = None
cache_prompt: Optional[bool] = None
n_predict: Optional[int] = None
top_k: Optional[int] = None
top_p: Optional[float] = None
min_p: Optional[float] = None
tfs_z: Optional[float] = None
typical_p: Optional[float] = None
temperature: Optional[float] = None
dynatemp_range: Optional[float] = None
dynatemp_exponent: Optional[float] = None
repeat_last_n: Optional[int] = None
repeat_penalty: Optional[float] = None
frequency_penalty: Optional[float] = None
presence_penalty: Optional[float] = None
mirostat: Optional[bool] = None
mirostat_tau: Optional[float] = None
mirostat_eta: Optional[float] = None
penalize_nl: Optional[bool] = None
n_keep: Optional[int] = None
seed: Optional[int] = None

grammar: Optional[str] = None
json_schema: Optional[Json] = None
Loading