Skip to content
This repository was archived by the owner on Dec 11, 2025. It is now read-only.

Commit ac00d52

Browse files
authored
Merge pull request #81 from Not-Diamond/ENG-2023_update-langchain
Update langchain and added tool calling for gpt 4.5
2 parents 8774809 + b56a05a commit ac00d52

66 files changed

Lines changed: 14779 additions & 16130 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/all-sdk-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828

2929
strategy:
3030
matrix:
31-
python-version: ["3.10", "3.11", "3.12", "3.13"]
31+
python-version: ["3.10", "3.11", "3.12"]
3232
steps:
3333
- uses: actions/checkout@v4
3434
- name: Set up Python ${{ matrix.python-version }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ dist/
99
.vscode/
1010
venv/
1111
.venv/
12+
.idea/

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ repos:
2424
hooks:
2525
- id: flake8
2626
args: [--max-line-length=130]
27-
exclude: ^(cookbooks|docs)
27+
exclude: ^(cookbooks|docs|tests/conftest.py)

notdiamond/llms/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
)
2222

2323
# Details: https://python.langchain.com/v0.1/docs/guides/development/pydantic_compatibility/
24-
from pydantic.v1 import BaseModel
24+
from pydantic import BaseModel
2525
from pydantic_partial import create_partial_model
2626

2727
from notdiamond import settings

notdiamond/settings.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,8 @@
6363
"gpt-4-turbo-preview",
6464
"gpt-4-0125-preview",
6565
"gpt-4-1106-preview",
66-
# Need to update langchain-openai to >=0.3.9 to support these
67-
# "gpt-4.5-preview",
68-
# "gpt-4.5-preview-2025-02-27"
66+
"gpt-4.5-preview",
67+
"gpt-4.5-preview-2025-02-27",
6968
],
7069
"support_response_model": [
7170
"gpt-3.5-turbo",

poetry.lock

Lines changed: 1468 additions & 1798 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,29 @@ pandas = "^2.2.2"
1616
pydantic-partial = "^0.5.5"
1717
cryptography = ">=44.0.1"
1818
tiktoken = ">=0.8.0,<0.9.0"
19-
langchain = { version = ">=0.2.7", optional = true }
20-
langchain-google-genai = { version = ">=1.0.7", optional = true }
21-
langchain-openai = { version = "^0.1.16", optional = true }
22-
langchain-anthropic = { version = "^0.1.20", optional = true }
23-
langchain-community = { version = "^0.2.16", optional = true }
24-
langchain-mistralai = { version = "^0.1.10", optional = true }
25-
langchain-together = { version = "^0.1.4", optional = true }
26-
langchain-cohere = { version = "^0.1.9", optional = true }
19+
langchain = { version = ">=0.3.22", optional = true }
20+
langchain-google-genai = { version = ">=2.1.2", optional = true }
21+
langchain-openai = { version = ">=0.3.9", optional = true }
22+
langchain-anthropic = { version = ">=0.3.10", optional = true }
23+
langchain-community = { version = ">=0.3.20", optional = true }
24+
langchain-mistralai = { version = ">=0.2.10", optional = true }
25+
langchain-together = { version = ">=0.3.0", optional = true }
26+
langchain-cohere = { version = ">=0.4.3", optional = true }
2727
requests = ">=2.31"
2828
optuna = { version = "^4.1.0", optional = true }
29-
ragas = { extras = ["all"], version = "^0.2.6", optional = true }
29+
ragas = { version = "^0.2.6", optional = true }
3030
unstructured = { extras = [
3131
"local-inference",
3232
], version = "^0.16.5", optional = true }
3333
onnxruntime = { version = "<1.20", optional = true }
3434
python-multipart = { version = "0.0.18", extras = ["rag"] }
3535
llama-index = { version = "^0.12.25", optional = true }
36-
r2r = "3.5.6"
3736

3837
[tool.poetry.group.test.dependencies]
3938
pytest = "^8.0.0"
4039
pytest-asyncio = "^0.23.6"
4140
pytest-mock = "^3.14.0"
42-
openai = ">=1.0.0"
41+
openai = ">=1.66.3"
4342
coverage = "^7.6.0"
4443
pytest-recording = "^0.13.2"
4544
pytest-timeout = "^2.3.1"

tests/conftest.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,23 @@ def openai_tools_fixture():
9595
return [add_tool]
9696

9797

98+
@pytest.fixture
99+
def get_stock_price_tool_fixture():
100+
"""Fixture that creates a tool for getting stock prices."""
101+
stock_tool = {
102+
"name": "get_stock_price",
103+
"description": "Get current stock price for a provided ticker symbol from Yahoo Finance using the yahooquery Python library.",
104+
"parameters": {
105+
"type": "object",
106+
"properties": {"ticker": {"type": "string"}},
107+
"required": ["ticker"],
108+
"additionalProperties": False,
109+
},
110+
}
111+
112+
return [stock_tool]
113+
114+
98115
@pytest.fixture
99116
def response_model():
100117
class Joke(BaseModel):

tests/test_components/test_llms/cassettes/test_llm_request/test_async_llm_invoke_with_latency_tracking_success.yaml

Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,23 @@ interactions:
66
null}], "metric": "accuracy", "max_model_depth": 1, "hash_content": false}'
77
headers:
88
User-Agent:
9-
- Python-SDK/0.3.41
9+
- Python-SDK/0.4.2
1010
content-type:
1111
- application/json
1212
method: POST
1313
uri: https://staging-api.notdiamond.ai/v2/modelRouter/modelSelect
1414
response:
1515
body:
16-
string: '{"providers":[{"provider":"openai","model":"gpt-3.5-turbo"}],"session_id":"9d8c1977-c521-414d-ad32-9b4c69269fed"}'
16+
string: '{"providers":[{"provider":"openai","model":"gpt-3.5-turbo"}],"session_id":"a6c4cc9a-990f-4602-837c-61f9cc65f641"}'
1717
headers:
1818
CF-RAY:
19-
- 925cfc694d5d5a59-VIE
19+
- 92a07723aa105b8d-VIE
2020
Connection:
2121
- keep-alive
2222
Content-Type:
2323
- application/json
2424
Date:
25-
- Tue, 25 Mar 2025 08:19:55 GMT
25+
- Wed, 02 Apr 2025 12:52:47 GMT
2626
Server:
2727
- cloudflare
2828
Transfer-Encoding:
@@ -36,16 +36,14 @@ interactions:
3636
content-length:
3737
- '113'
3838
rndr-id:
39-
- 3dd2bf47-6e7c-4d95
39+
- cf1e8d4d-d176-4709
4040
x-render-origin-server:
4141
- uvicorn
4242
status:
4343
code: 200
4444
message: OK
4545
- request:
46-
body: '{"messages": [{"content": "Prompt: Tell me a joke.", "role": "user"}],
47-
"model": "gpt-3.5-turbo", "max_tokens": 10, "n": 1, "stream": false, "temperature":
48-
0.7}'
46+
body: '{"messages":[{"content":"Prompt: Tell me a joke.","role":"user"}],"model":"gpt-3.5-turbo","stream":false}'
4947
headers:
5048
accept:
5149
- application/json
@@ -54,13 +52,13 @@ interactions:
5452
connection:
5553
- keep-alive
5654
content-length:
57-
- '159'
55+
- '105'
5856
content-type:
5957
- application/json
6058
host:
6159
- api.openai.com
6260
user-agent:
63-
- AsyncOpenAI/Python 1.68.2
61+
- AsyncOpenAI/Python 1.60.2
6462
x-stainless-arch:
6563
- x64
6664
x-stainless-async:
@@ -70,9 +68,7 @@ interactions:
7068
x-stainless-os:
7169
- Linux
7270
x-stainless-package-version:
73-
- 1.68.2
74-
x-stainless-read-timeout:
75-
- '120.0'
71+
- 1.60.2
7672
x-stainless-retry-count:
7773
- '0'
7874
x-stainless-runtime:
@@ -83,34 +79,34 @@ interactions:
8379
uri: https://api.openai.com/v1/chat/completions
8480
response:
8581
body:
86-
string: "{\n \"id\": \"chatcmpl-BEtnnWjXmdkH9MGiaCSrzAPWPKofR\",\n \"object\":
87-
\"chat.completion\",\n \"created\": 1742890795,\n \"model\": \"gpt-3.5-turbo-0125\",\n
82+
string: "{\n \"id\": \"chatcmpl-BHrsGFnVhe9JvTv5cTyMAXRDnkhhX\",\n \"object\":
83+
\"chat.completion\",\n \"created\": 1743598368,\n \"model\": \"gpt-3.5-turbo-0125\",\n
8884
\ \"choices\": [\n {\n \"index\": 0,\n \"message\": {\n \"role\":
89-
\"assistant\",\n \"content\": \"Why couldn't the bicycle stand up by
90-
itself?\\n\\n\",\n \"refusal\": null,\n \"annotations\": []\n
91-
\ },\n \"logprobs\": null,\n \"finish_reason\": \"length\"\n
85+
\"assistant\",\n \"content\": \"Why did the scarecrow win an award?\\nBecause
86+
he was outstanding in his field!\",\n \"refusal\": null,\n \"annotations\":
87+
[]\n },\n \"logprobs\": null,\n \"finish_reason\": \"stop\"\n
9288
\ }\n ],\n \"usage\": {\n \"prompt_tokens\": 14,\n \"completion_tokens\":
93-
10,\n \"total_tokens\": 24,\n \"prompt_tokens_details\": {\n \"cached_tokens\":
89+
18,\n \"total_tokens\": 32,\n \"prompt_tokens_details\": {\n \"cached_tokens\":
9490
0,\n \"audio_tokens\": 0\n },\n \"completion_tokens_details\":
9591
{\n \"reasoning_tokens\": 0,\n \"audio_tokens\": 0,\n \"accepted_prediction_tokens\":
9692
0,\n \"rejected_prediction_tokens\": 0\n }\n },\n \"service_tier\":
9793
\"default\",\n \"system_fingerprint\": null\n}\n"
9894
headers:
9995
CF-RAY:
100-
- 925cfc6dfaf25acf-VIE
96+
- 92a0772869bfd0f2-SOF
10197
Connection:
10298
- keep-alive
10399
Content-Type:
104100
- application/json
105101
Date:
106-
- Tue, 25 Mar 2025 08:19:55 GMT
102+
- Wed, 02 Apr 2025 12:52:48 GMT
107103
Server:
108104
- cloudflare
109105
Set-Cookie:
110-
- __cf_bm=27OqbJBi6rbSwSFakwNrnXdTx4amaL5Q5NBo5ITiOyM-1742890795-1.0.1.1-vnLFmpWppCuaIVsI32nRgwfpdQVtcZ855roW3Aa9TLU9CANLQhprKag2YZmVk1kF90Z8nJgJCFZonZsmjJwJ4i8o__Ff27WimZnWQ4bhZIg;
111-
path=/; expires=Tue, 25-Mar-25 08:49:55 GMT; domain=.api.openai.com; HttpOnly;
106+
- __cf_bm=prCQkj6QaXaNCcoJQihkW2Bij8KD3r5V93SDPloGzTY-1743598368-1.0.1.1-dVbJRn1vgFoSmHLYYQAXxmnzhM7ZHtl.wmAUPZc3MwBjS38D9AMOLxiiLBDfySNbyBJICDd9UvZoYX7TUy0eW3l7l3ZFBxGyHkntXsBeQCM;
107+
path=/; expires=Wed, 02-Apr-25 13:22:48 GMT; domain=.api.openai.com; HttpOnly;
112108
Secure; SameSite=None
113-
- _cfuvid=Q3pvjMF3pfyC3NCFMhS61FBlhDPgCbniTqiw2nUJYVA-1742890795568-0.0.1.1-604800000;
109+
- _cfuvid=RMfE4HeYit80e_VzMK5IFqbHsGAl1BUpiwEEOr.nEqs-1743598368623-0.0.1.1-604800000;
114110
path=/; domain=.api.openai.com; HttpOnly; Secure; SameSite=None
115111
Transfer-Encoding:
116112
- chunked
@@ -123,11 +119,11 @@ interactions:
123119
cf-cache-status:
124120
- DYNAMIC
125121
content-length:
126-
- '842'
122+
- '869'
127123
openai-organization:
128124
- not-diamond-bdz8cg
129125
openai-processing-ms:
130-
- '232'
126+
- '402'
131127
openai-version:
132128
- '2020-10-01'
133129
strict-transport-security:
@@ -145,15 +141,15 @@ interactions:
145141
x-ratelimit-reset-tokens:
146142
- 0s
147143
x-request-id:
148-
- req_387f06b77cf31e7f9668ef3ad08161d8
144+
- req_4c614b950feb80d71f814b52153867bf
149145
status:
150146
code: 200
151147
message: OK
152148
- request:
153-
body: '{"session_id": "9d8c1977-c521-414d-ad32-9b4c69269fed", "provider": {"provider":
149+
body: '{"session_id": "a6c4cc9a-990f-4602-837c-61f9cc65f641", "provider": {"provider":
154150
"openai", "model": "gpt-3.5-turbo", "is_custom": false, "context_length": null,
155151
"input_price": null, "output_price": null, "latency": null}, "feedback": {"tokens_per_second":
156-
34.713605035147786}}'
152+
24.643946395404058}}'
157153
headers:
158154
Accept:
159155
- '*/*'
@@ -164,24 +160,24 @@ interactions:
164160
Content-Length:
165161
- '275'
166162
User-Agent:
167-
- Python-SDK/0.3.41
163+
- Python-SDK/0.4.2
168164
content-type:
169165
- application/json
170166
method: POST
171167
uri: https://staging-api.notdiamond.ai/v2/report/metrics/latency
172168
response:
173169
body:
174-
string: '{"detail":"requestID=80afc164-0f1d-4c56, Session 9d8c1977-c521-414d-ad32-9b4c69269fed
170+
string: '{"detail":"requestID=731fc3fe-1403-4396, Session a6c4cc9a-990f-4602-837c-61f9cc65f641
175171
does not belong to user d6b6f4db-9cd9-4a33-b885-506685cd2d34."}'
176172
headers:
177173
CF-RAY:
178-
- 925cfc710b24d0ce-SOF
174+
- 92a0772caf0fd0da-SOF
179175
Connection:
180176
- keep-alive
181177
Content-Type:
182178
- application/json
183179
Date:
184-
- Tue, 25 Mar 2025 08:19:56 GMT
180+
- Wed, 02 Apr 2025 12:52:49 GMT
185181
Server:
186182
- cloudflare
187183
Transfer-Encoding:
@@ -191,7 +187,7 @@ interactions:
191187
cf-cache-status:
192188
- DYNAMIC
193189
rndr-id:
194-
- 80afc164-0f1d-4c56
190+
- 731fc3fe-1403-4396
195191
vary:
196192
- Accept-Encoding
197193
x-render-origin-server:

0 commit comments

Comments
 (0)