Skip to content

Commit 2b42121

Browse files
jsonbaileyclaude
andcommitted
fix: Modernize server-ai package and provider READMEs to current SDK
- packages/sdk/server-ai/README.md, packages/ai-providers/server-ai-openai/README.md, packages/ai-providers/server-ai-langchain/README.md - Replace nonexistent `from ldai import init` / `init(ld_client)` with `from ldai import LDAIClient` / `LDAIClient(ld_client)` in both provider READMEs - Update server-ai README: model.invoke() -> model.run() and .message.content -> .content; remove nonexistent model.get_messages(); replace nonexistent LangChainProvider class with create_langchain_model + bare get_ai_metrics_from_response; swap track_metrics_of / track_metrics_of_async arg order to (extractor, callable); canonicalize from ldai.providers.types -> from ldai.providers + from ldai.tracker - Fix LangChain README: align manual-runner example to import LangChainModelRunner that it actually uses - Fix `result.metrics.tokens` -> `result.metrics.usage` in both provider READMEs (Python LDAIMetricSummary uses .usage; the input LDAIMetrics dataclass uses .tokens - asymmetric) Refs AIC-2383 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 612d518 commit 2b42121

3 files changed

Lines changed: 20 additions & 20 deletions

File tree

packages/ai-providers/server-ai-langchain/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ pip install langchain-google-genai
3737
```python
3838
import asyncio
3939
from ldclient import LDClient, Config, Context
40-
from ldai import init
40+
from ldai import LDAIClient
4141
from ldai.models import AICompletionConfigDefault, ModelConfig, ProviderConfig
4242

4343
# Initialize LaunchDarkly client
4444
ld_client = LDClient(Config("your-sdk-key"))
45-
ai_client = init(ld_client)
45+
ai_client = LDAIClient(ld_client)
4646

4747
context = Context.builder("user-123").build()
4848

@@ -84,11 +84,11 @@ if model:
8484
### Using the runner directly
8585

8686
If you need to construct a runner manually (e.g. for testing), you can use
87-
`LangChainRunnerFactory` from the `ldai_langchain` package:
87+
`LangChainModelRunner` from the `ldai_langchain` package:
8888

8989
```python
9090
from langchain_openai import ChatOpenAI
91-
from ldai_langchain import LangChainRunnerFactory
91+
from ldai_langchain import LangChainModelRunner
9292

9393
llm = ChatOpenAI(model="gpt-4", temperature=0.7)
9494
runner = LangChainModelRunner(llm)
@@ -126,7 +126,7 @@ model = await ai_client.create_model("ai-config-key", context)
126126
if model:
127127
result = await model.run("Explain feature flags.")
128128
# Metrics are tracked automatically; access them via result.metrics
129-
print(result.metrics.tokens)
129+
print(result.metrics.usage)
130130
```
131131

132132
### Static Utility Methods

packages/ai-providers/server-ai-openai/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ pip install launchdarkly-server-sdk-ai-openai
2424
```python
2525
import asyncio
2626
from ldclient import LDClient, Config, Context
27-
from ldai import init
27+
from ldai import LDAIClient
2828
from ldai.models import AICompletionConfigDefault, ModelConfig, ProviderConfig
2929

3030
# Initialize LaunchDarkly client
3131
ld_client = LDClient(Config("your-sdk-key"))
32-
ai_client = init(ld_client)
32+
ai_client = LDAIClient(ld_client)
3333

3434
context = Context.builder("user-123").build()
3535

@@ -112,7 +112,7 @@ model = await ai_client.create_model("ai-config-key", context)
112112
if model:
113113
result = await model.run("Explain feature flags.")
114114
# Metrics are tracked automatically; access them via result.metrics
115-
print(result.metrics.tokens)
115+
print(result.metrics.usage)
116116
```
117117

118118
### Static Utility Methods

packages/sdk/server-ai/README.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,15 @@ async def main():
123123
)
124124

125125
if model:
126-
# Simple conversation flow - metrics are automatically tracked by invoke()
127-
response1 = await model.invoke('I need help with my order')
128-
print(response1.message.content)
126+
# Simple conversation flow - metrics are automatically tracked by run()
127+
response1 = await model.run('I need help with my order')
128+
print(response1.content)
129129

130-
response2 = await model.invoke("What's the status?")
131-
print(response2.message.content)
130+
response2 = await model.run("What's the status?")
131+
print(response2.content)
132132

133133
# Access conversation history
134-
messages = model.get_messages()
134+
messages = model.get_config().messages
135135
print(f'Conversation has {len(messages)} messages')
136136

137137
asyncio.run(main())
@@ -146,21 +146,20 @@ For more control, you can use the configuration directly with AI providers. We r
146146
```python
147147
import asyncio
148148
from ldai import LDAIClient, AICompletionConfigDefault, ModelConfig
149-
from ldai.providers.types import LDAIMetrics, TokenUsage
150149

151-
from ldai_langchain import LangChainProvider
150+
from ldai_langchain import create_langchain_model, get_ai_metrics_from_response
152151

153152
async def main():
154153
ai_config = ai_client.completion_config(ai_config_key, context, default)
155154

156155
# Create LangChain model from configuration
157-
llm = await LangChainProvider.create_langchain_model(ai_config)
156+
llm = create_langchain_model(ai_config)
158157

159158
# Use with tracking (sync invoke). Mint a tracker once per AI run.
160159
tracker = ai_config.create_tracker()
161160
response = tracker.track_metrics_of(
161+
get_ai_metrics_from_response,
162162
lambda: llm.invoke(messages),
163-
lambda result: LangChainProvider.get_ai_metrics_from_response(result)
164163
)
165164

166165
print('AI Response:', response.content)
@@ -173,7 +172,8 @@ asyncio.run(main())
173172
```python
174173
import asyncio
175174
from ldai import LDAIClient, AICompletionConfigDefault, ModelConfig
176-
from ldai.providers.types import LDAIMetrics, TokenUsage
175+
from ldai.providers import LDAIMetrics
176+
from ldai.tracker import TokenUsage
177177

178178
async def main():
179179
ai_config = ai_client.completion_config(ai_config_key, context, default)
@@ -200,8 +200,8 @@ async def main():
200200
# Mint a tracker once per AI run.
201201
tracker = ai_config.create_tracker()
202202
result = await tracker.track_metrics_of_async(
203+
map_custom_provider_metrics,
203204
call_custom_provider,
204-
map_custom_provider_metrics
205205
)
206206

207207
print('AI Response:', result.content)

0 commit comments

Comments
 (0)