Skip to content

Commit

Permalink
Remove stream parameters for now (#126)
Browse files Browse the repository at this point in the history
* Remove stream parameter from sdk call

Non-streaming isn't currently supported so force sdk to use streaming
always. Also add temperature and max tokens.

* fix up completions plus add example

* fix dependabot security issue
  • Loading branch information
justin1121 authored Sep 27, 2023
1 parent 8eaa845 commit 7451bbe
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 6 deletions.
12 changes: 12 additions & 0 deletions examples/llama/llama.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,17 @@
{"role": "system", "content": "you are a happy helpful assistant"},
],
token,
max_tokens=16,
temperature=0.8,
):
print(msg)


for msg in c.completions(
"<s>[INST] <<SYS>>You are a helpful Assistant.<</SYS>>"
"\n\nWhat is the Capital of France? [/INST]",
token,
max_tokens=16,
temperature=0.8,
):
print(msg)
27 changes: 23 additions & 4 deletions pycape/llms/llms.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ async def completions(
self,
prompt: str,
token: str,
stream=True,
max_tokens=16,
temperature=0.8,
model="llama",
pcrs=None,
):
Expand All @@ -100,7 +101,15 @@ async def completions(

data = crypto.envelope_encrypt(
self.ctx.public_key,
{"request": {"prompt": prompt, "stream": stream}, "user_key": user_key},
{
"request": {
"prompt": prompt,
"stream": True,
"max_tokens": max_tokens,
"temperature": temperature,
},
"user_key": user_key,
},
)
data = base64.b64encode(data).decode()

Expand Down Expand Up @@ -136,7 +145,8 @@ async def chat_completions(
self,
messages: Union[str, List[Dict[str, Any]]],
token: str,
stream=True,
max_tokens=16,
temperature=0.8,
model="llama",
pcrs=None,
):
Expand All @@ -147,7 +157,15 @@ async def chat_completions(

data = crypto.envelope_encrypt(
self.ctx.public_key,
{"request": {"messages": messages, "stream": stream}, "user_key": user_key},
{
"request": {
"messages": messages,
"stream": True,
"max_tokens": max_tokens,
"temperature": temperature,
},
"user_key": user_key,
},
)
data = base64.b64encode(data).decode()

Expand Down Expand Up @@ -261,6 +279,7 @@ async def bootstrap(self, pcrs: Optional[Dict[str, List[str]]] = None):

return attestation_doc

_logger.warning("received public key, no attestation performed...")
self._public_key = msg.data["public_key"].encode()

@property
Expand Down
2 changes: 1 addition & 1 deletion requirements/base.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ websockets
pyOpenSSL>=23.2.0
cose
certifi>=2023.7.22
requests
requests>=2.31.0
synchronicity>=0.5.3
websockets
pydantic
Expand Down
2 changes: 1 addition & 1 deletion requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pydantic-core==2.6.3
# via pydantic
pyopenssl==23.2.0
# via -r requirements/base.in
requests==2.28.1
requests==2.31.0
# via -r requirements/base.in
file:./serdio
# via -r requirements/base.in
Expand Down

0 comments on commit 7451bbe

Please sign in to comment.