Skip to content

Commit cbe3802

Browse files
authored
chore: Modernize server-ai package and provider READMEs to current SDK (#184)
1 parent f79341a commit cbe3802

3 files changed

Lines changed: 17 additions & 21 deletions

File tree

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

Lines changed: 4 additions & 4 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)

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

Lines changed: 2 additions & 2 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

packages/sdk/server-ai/README.md

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -123,16 +123,12 @@ 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)
132-
133-
# Access conversation history
134-
messages = model.get_messages()
135-
print(f'Conversation has {len(messages)} messages')
130+
response2 = await model.run("What's the status?")
131+
print(response2.content)
136132

137133
asyncio.run(main())
138134
```
@@ -146,21 +142,20 @@ For more control, you can use the configuration directly with AI providers. We r
146142
```python
147143
import asyncio
148144
from ldai import LDAIClient, AICompletionConfigDefault, ModelConfig
149-
from ldai.providers.types import LDAIMetrics, TokenUsage
150145

151-
from ldai_langchain import LangChainProvider
146+
from ldai_langchain import create_langchain_model, get_ai_metrics_from_response
152147

153148
async def main():
154149
ai_config = ai_client.completion_config(ai_config_key, context, default)
155150

156151
# Create LangChain model from configuration
157-
llm = await LangChainProvider.create_langchain_model(ai_config)
152+
llm = create_langchain_model(ai_config)
158153

159154
# Use with tracking (sync invoke). Mint a tracker once per AI run.
160155
tracker = ai_config.create_tracker()
161156
response = tracker.track_metrics_of(
157+
get_ai_metrics_from_response,
162158
lambda: llm.invoke(messages),
163-
lambda result: LangChainProvider.get_ai_metrics_from_response(result)
164159
)
165160

166161
print('AI Response:', response.content)
@@ -173,7 +168,8 @@ asyncio.run(main())
173168
```python
174169
import asyncio
175170
from ldai import LDAIClient, AICompletionConfigDefault, ModelConfig
176-
from ldai.providers.types import LDAIMetrics, TokenUsage
171+
from ldai.providers import LDAIMetrics
172+
from ldai.tracker import TokenUsage
177173

178174
async def main():
179175
ai_config = ai_client.completion_config(ai_config_key, context, default)
@@ -200,8 +196,8 @@ async def main():
200196
# Mint a tracker once per AI run.
201197
tracker = ai_config.create_tracker()
202198
result = await tracker.track_metrics_of_async(
199+
map_custom_provider_metrics,
203200
call_custom_provider,
204-
map_custom_provider_metrics
205201
)
206202

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

0 commit comments

Comments
 (0)