Skip to content

Commit

Permalink
Add RunnableSequence.stream
Browse files Browse the repository at this point in the history
  • Loading branch information
tibor-reiss committed May 28, 2024
1 parent 9103977 commit ebd8556
Show file tree
Hide file tree
Showing 6 changed files with 315 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,13 @@
"span_name": "langchain.workflow",
"wrapper": aworkflow_wrapper,
},
{
"package": "langchain.schema.runnable",
"object": "RunnableSequence",
"method": "stream",
"span_name": "langchain.workflow",
"wrapper": workflow_wrapper,
},
{
"package": "langchain_core.language_models.llms",
"object": "LLM",
Expand Down
163 changes: 159 additions & 4 deletions packages/opentelemetry-instrumentation-langchain/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@ pytest-asyncio = "^0.23.5"
opentelemetry-sdk = "^1.23.0"
opentelemetry-instrumentation-openai = {path="../opentelemetry-instrumentation-openai", develop=true}
opentelemetry-instrumentation-bedrock = {path="../opentelemetry-instrumentation-bedrock", develop=true}
opentelemetry-instrumentation-cohere = {path = "../opentelemetry-instrumentation-cohere", develop=true}
text-generation = "^0.7.0"
anthropic = "^0.23.0"
boto3 = "1.34.88"
langchain-anthropic = "^0.1.11"
langchain-openai = "^0.1.6"
langchain-cohere = "^0.1.5"
pydantic = "^2.7.1"

[build-system]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
interactions:
- request:
body: '{"message": "tell me a short joke", "stream": true, "model": "command-r",
"chat_history": [{"role": "System", "message": "You are a helpful assistant"}]}'
headers:
accept:
- '*/*'
accept-encoding:
- gzip, deflate
connection:
- keep-alive
content-length:
- '153'
content-type:
- application/json
host:
- api.cohere.com
user-agent:
- python-httpx/0.27.0
x-client-name:
- langchain:partner
x-fern-language:
- Python
x-fern-sdk-name:
- cohere
x-fern-sdk-version:
- 5.5.3
method: POST
uri: https://api.cohere.com/v1/chat
response:
body:
string: '{"is_finished":false,"event_type":"stream-start","generation_id":"8681736d-8a61-4220-b030-eadfe451f55c"}
{"is_finished":false,"event_type":"text-generation","text":"What"}
{"is_finished":false,"event_type":"text-generation","text":" do"}
{"is_finished":false,"event_type":"text-generation","text":" you"}
{"is_finished":false,"event_type":"text-generation","text":" call"}
{"is_finished":false,"event_type":"text-generation","text":" a"}
{"is_finished":false,"event_type":"text-generation","text":" factory"}
{"is_finished":false,"event_type":"text-generation","text":" that"}
{"is_finished":false,"event_type":"text-generation","text":" makes"}
{"is_finished":false,"event_type":"text-generation","text":" distinctly"}
{"is_finished":false,"event_type":"text-generation","text":" average"}
{"is_finished":false,"event_type":"text-generation","text":" products"}
{"is_finished":false,"event_type":"text-generation","text":"?"}
{"is_finished":false,"event_type":"text-generation","text":"\n\n*"}
{"is_finished":false,"event_type":"text-generation","text":"An"}
{"is_finished":false,"event_type":"text-generation","text":" adequate"}
{"is_finished":false,"event_type":"text-generation","text":"-"}
{"is_finished":false,"event_type":"text-generation","text":"tor"}
{"is_finished":false,"event_type":"text-generation","text":"ium"}
{"is_finished":false,"event_type":"text-generation","text":"*."}
{"is_finished":true,"event_type":"stream-end","response":{"response_id":"00721a08-a2e4-451a-92ee-82a55bf43526","text":"What
do you call a factory that makes distinctly average products?\n\n*An adequate-torium*.","generation_id":"8681736d-8a61-4220-b030-eadfe451f55c","chat_history":[{"role":"SYSTEM","message":"You
are a helpful assistant"},{"role":"USER","message":"tell me a short joke"},{"role":"CHATBOT","message":"What
do you call a factory that makes distinctly average products?\n\n*An adequate-torium*."}],"finish_reason":"COMPLETE","meta":{"api_version":{"version":"1"},"billed_units":{"input_tokens":10,"output_tokens":21},"tokens":{"input_tokens":79,"output_tokens":21}}},"finish_reason":"COMPLETE"}
'
headers:
Alt-Svc:
- h3=":443"; ma=2592000,h3-29=":443"; ma=2592000
Via:
- 1.1 google
access-control-expose-headers:
- X-Debug-Trace-ID
cache-control:
- no-cache, no-store, no-transform, must-revalidate, private, max-age=0
content-type:
- application/stream+json
date:
- Tue, 28 May 2024 08:09:02 GMT
expires:
- Thu, 01 Jan 1970 00:00:00 UTC
pragma:
- no-cache
server:
- envoy
transfer-encoding:
- chunked
vary:
- Origin
x-accel-expires:
- '0'
x-debug-trace-id:
- 95bf12ce0cc85c5a248873cb342c8112
x-endpoint-monthly-call-limit:
- '1000'
x-envoy-upstream-service-time:
- '75'
x-trial-endpoint-call-limit:
- '10'
x-trial-endpoint-call-remaining:
- '8'
status:
code: 200
message: OK
version: 1
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from opentelemetry.instrumentation.openai import OpenAIInstrumentor
from opentelemetry.instrumentation.bedrock import BedrockInstrumentor
from opentelemetry.instrumentation.langchain import LangchainInstrumentor
from opentelemetry.instrumentation.cohere import CohereInstrumentor

pytest_plugins = []

Expand All @@ -25,6 +26,7 @@ def exporter():
OpenAIInstrumentor().instrument()
BedrockInstrumentor().instrument()
LangchainInstrumentor().instrument()
CohereInstrumentor().instrument()

return exporter

Expand All @@ -40,6 +42,8 @@ def environment():
os.environ["OPENAI_API_KEY"] = "test_api_key"
if not os.environ.get("ANTHROPIC_API_KEY"):
os.environ["ANTHROPIC_API_KEY"] = "test"
if not os.environ.get("COHERE_API_KEY"):
os.environ["COHERE_API_KEY"] = "test"


@pytest.fixture(scope="module")
Expand Down
Loading

0 comments on commit ebd8556

Please sign in to comment.