-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Stripping trailing null bytes + batch size of 1 = working code
- Loading branch information
1 parent
c26b5a5
commit 321b67a
Showing
4 changed files
with
80 additions
and
43 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,44 +1,62 @@ | ||
import os | ||
|
||
os.environ["LANGCHAIN_PROJECT"] = "llm_messages_test_py" | ||
os.environ["LANGSMITH_USE_PYO3_CLIENT"] = "true" | ||
|
||
from langsmith import traceable | ||
from langsmith import Client, traceable | ||
|
||
client = Client( | ||
api_url="https://beta.api.smith.langchain.com", | ||
api_key=os.environ["LANGCHAIN_API_KEY"], | ||
) | ||
|
||
|
||
@traceable | ||
@traceable(client=client) | ||
def format_prompt(subject): | ||
return [ | ||
{ | ||
"role": "system", | ||
"content": "You are a helpful assistant.", | ||
}, | ||
{ | ||
"role": "user", | ||
"content": f"What's a good name for a store that sells {subject}?" | ||
} | ||
] | ||
|
||
@traceable(run_type="llm") | ||
return [ | ||
{ | ||
"role": "system", | ||
"content": "You are a helpful assistant.", | ||
}, | ||
{ | ||
"role": "user", | ||
"content": f"What's a good name for a store that sells {subject}?", | ||
}, | ||
] | ||
|
||
|
||
@traceable(run_type="llm", client=client) | ||
def invoke_llm(messages): | ||
return { | ||
"choices": [ | ||
{ | ||
"message": { | ||
"role": "assistant", | ||
"content": "Sure, how about 'Rainbow Socks'?" | ||
} | ||
} | ||
] | ||
} | ||
|
||
@traceable | ||
return { | ||
"choices": [ | ||
{ | ||
"message": { | ||
"role": "assistant", | ||
"content": "Sure, how about 'Rainbow Socks'?", | ||
} | ||
} | ||
] | ||
} | ||
|
||
|
||
@traceable(client=client) | ||
def parse_output(response): | ||
return response["choices"][0]["message"]["content"] | ||
return response["choices"][0]["message"]["content"] | ||
|
||
|
||
@traceable | ||
@traceable(client=client) | ||
def run_pipeline(): | ||
messages = format_prompt("colorful socks") | ||
response = invoke_llm(messages) | ||
return parse_output(response) | ||
messages = format_prompt("colorful socks") | ||
response = invoke_llm(messages) | ||
result = parse_output(response) | ||
|
||
import time | ||
|
||
time.sleep(2) | ||
|
||
return result | ||
|
||
|
||
if __name__ == "__main__": | ||
run_pipeline() | ||
print("running pipeline") | ||
run_pipeline() |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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