Skip to content

Commit 31ff531

Browse files
authored
Merge pull request #207 from Scale3-Labs/development
Release Ollama + disable vendor specific functions
2 parents d76351d + 15ac7a1 commit 31ff531

File tree

36 files changed

+688
-80
lines changed

36 files changed

+688
-80
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ dev = [
4949
"cohere",
5050
"qdrant_client",
5151
"weaviate-client",
52+
"ollama"
5253
]
5354

5455
test = [

src/examples/inspect_ai_example/basic_eval.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
from inspect_ai.scorer import model_graded_qa
66
from inspect_ai.solver import chain_of_thought, generate, self_critique
77

8-
from langtrace_python_sdk.extensions.langtrace_filesystem import \
9-
LangTraceFileSystem
8+
from langtrace_python_sdk.extensions.langtrace_filesystem import LangTraceFileSystem
109

1110
# from langtrace_python_sdk import langtrace
1211

@@ -20,9 +19,6 @@
2019
def security_guide():
2120
return Task(
2221
dataset=csv_dataset("langtracefs://clxc2mxu6000lpc7ntsvcjvp9"),
23-
plan=[
24-
chain_of_thought(),
25-
self_critique()
26-
],
27-
scorer=model_graded_qa()
22+
plan=[chain_of_thought(), self_critique()],
23+
scorer=model_graded_qa(),
2824
)

src/examples/langchain_example/basic.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@
88
from langchain_openai import ChatOpenAI, OpenAIEmbeddings
99

1010
from langtrace_python_sdk import langtrace
11-
from langtrace_python_sdk.utils.with_root_span import (
12-
with_langtrace_root_span,
13-
with_additional_attributes,
14-
)
11+
from langtrace_python_sdk.utils.with_root_span import with_langtrace_root_span
12+
from openai import OpenAI
1513

1614
_ = load_dotenv(find_dotenv())
1715

18-
langtrace.init()
16+
langtrace.init(
17+
write_spans_to_console=False,
18+
disable_tracing_for_functions={"langchain": ["RunnableSequence.invoke"]},
19+
)
1920

2021

2122
def api_call_1():
@@ -29,7 +30,8 @@ def api_call_1():
2930
output_parser = StrOutputParser()
3031
chain = prompt | llm | output_parser
3132
res = chain.invoke({"input": "how can langsmith help with testing?"})
32-
print(res)
33+
# print(res)
34+
return res
3335

3436

3537
def api_call_2():
@@ -43,13 +45,26 @@ def api_call_2():
4345
output_parser = StrOutputParser()
4446
chain = prompt | llm | output_parser
4547
res = chain.invoke({"input": "how can langsmith help with testing?"})
46-
print(res)
48+
# print(res)
49+
return res
4750

4851

4952
@with_langtrace_root_span()
5053
def basic_app():
5154
api_call_1()
52-
api_call_2()
55+
# api_call_2()
56+
client = OpenAI()
57+
response = client.chat.completions.create(
58+
model="gpt-4",
59+
messages=[
60+
{"role": "system", "content": "Talk like a pirate"},
61+
{"role": "user", "content": "Tell me a story in 3 sentences or less."},
62+
],
63+
# stream=True,
64+
stream=False,
65+
)
66+
67+
return response
5368

5469

5570
@with_langtrace_root_span()

src/examples/llamaindex_example/agent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
nest_asyncio.apply()
1414

15-
langtrace.init(write_spans_to_console=False)
15+
langtrace.init()
1616

1717

1818
def multiply(a: int, b: int) -> int:

src/examples/llamaindex_example/basic.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
_ = load_dotenv(find_dotenv())
88

99

10-
langtrace.init(write_spans_to_console=False)
10+
langtrace.init(
11+
disable_tracing_for_functions={
12+
"open_ai": ["openai.chat.completions.create"],
13+
}
14+
)
1115

1216

1317
@with_langtrace_root_span()
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from .basic import chat, async_chat, async_generate, generate, embed, async_embed
2+
from langtrace_python_sdk import with_langtrace_root_span
3+
import asyncio
4+
5+
6+
class OllamaRunner:
7+
@with_langtrace_root_span("OllamaRunner")
8+
def run(self):
9+
chat()
10+
generate()
11+
embed()
12+
asyncio.run(async_chat())
13+
asyncio.run(async_generate())
14+
asyncio.run(async_embed())
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
from langtrace_python_sdk import langtrace, with_langtrace_root_span
2+
import ollama
3+
from ollama import AsyncClient
4+
from dotenv import load_dotenv
5+
6+
load_dotenv()
7+
8+
langtrace.init(write_spans_to_console=False)
9+
10+
11+
def chat():
12+
response = ollama.chat(
13+
model="llama3",
14+
messages=[
15+
{
16+
"role": "user",
17+
"content": "hi",
18+
},
19+
],
20+
stream=True,
21+
)
22+
23+
return response
24+
25+
26+
async def async_chat():
27+
message = {"role": "user", "content": "Why is the sky blue?"}
28+
return await AsyncClient().chat(model="llama3", messages=[message])
29+
30+
31+
def generate():
32+
return ollama.generate(model="llama3", prompt="Why is the sky blue?")
33+
34+
35+
def async_generate():
36+
return AsyncClient().generate(model="llama3", prompt="Why is the sky blue?")
37+
38+
39+
def embed():
40+
return ollama.embeddings(
41+
model="llama3",
42+
prompt="cat",
43+
)
44+
45+
46+
async def async_embed():
47+
return await AsyncClient().embeddings(
48+
model="llama3",
49+
prompt="cat",
50+
)

src/examples/openai_example/chat_completion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,5 @@ def chat_completion():
4040
]
4141
result.append(content[0] if len(content) > 0 else "")
4242

43-
print("".join(result))
43+
# print("".join(result))
4444
return response

src/examples/pinecone_example/basic.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
with_additional_attributes,
1414
)
1515
from langtrace_python_sdk.utils.with_root_span import SendUserFeedback
16+
from opentelemetry.sdk.trace.export import ConsoleSpanExporter
1617

1718
_ = load_dotenv(find_dotenv())
1819
langtrace.init()

src/langtrace_python_sdk/__init__.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@
1515
"""
1616

1717
from langtrace_python_sdk import langtrace
18-
from langtrace_python_sdk.extensions.langtrace_filesystem import \
19-
LangTraceFileSystem
18+
from langtrace_python_sdk.extensions.langtrace_filesystem import LangTraceFileSystem
2019
from langtrace_python_sdk.utils.prompt_registry import get_prompt_from_registry
2120
from langtrace_python_sdk.utils.with_root_span import (
22-
SendUserFeedback, inject_additional_attributes, with_additional_attributes,
23-
with_langtrace_root_span)
21+
SendUserFeedback,
22+
inject_additional_attributes,
23+
with_additional_attributes,
24+
with_langtrace_root_span,
25+
)
2426

2527
__all__ = [
2628
"langtrace",

0 commit comments

Comments
 (0)