You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Create a LangChain provider from the AI configuration
62
-
provider =await LangChainProvider.create(config)
63
-
64
-
# Use the provider to invoke the model
65
-
from ldai.models import LDMessage
66
-
messages = [
67
-
LDMessage(role="system", content="You are a helpful assistant."),
68
-
LDMessage(role="user", content="Hello, how are you?"),
69
-
]
70
-
71
-
response =await provider.invoke_model(messages)
72
-
print(response.message.content)
50
+
# Create a ManagedModel backed by the LangChain provider
51
+
model =await ai_client.create_model(
52
+
"ai-config-key",
53
+
context,
54
+
AICompletionConfigDefault(
55
+
enabled=True,
56
+
model=ModelConfig("gpt-4"),
57
+
provider=ProviderConfig("langchain"),
58
+
),
59
+
)
60
+
61
+
if model:
62
+
result =await model.run("Hello, how are you?")
63
+
print(result.content)
73
64
74
65
asyncio.run(main())
75
66
```
76
67
77
68
## Usage
78
69
79
-
### Using LangChainProvider with the Create Factory
70
+
### Using `create_model` (recommended)
80
71
81
-
The simplest way to use the LangChain provider is with the static `create` factory method, which automatically creates the appropriate LangChain model based on your LaunchDarkly AI configuration:
72
+
The recommended entry point is `LDAIClient.create_model`, which evaluates a
73
+
LaunchDarkly AI config flag, selects the LangChain runner automatically, and
74
+
returns a `ManagedModel` that wraps the runner:
82
75
83
76
```python
84
-
from ldai_langchain import LangChainProvider
77
+
model =await ai_client.create_model("ai-config-key", context)
-`run(input, output_type=None) -> RunnerResult` — Run the model with a string prompt or list of `LDMessage` objects. Pass `output_type` (JSON schema dict) for structured output.
185
+
-`get_llm() -> BaseChatModel` — Return the underlying LangChain model.
198
186
199
-
-`create(ai_config: AIConfigKind, logger: Optional[Any] = None) -> LangChainProvider` - Factory method to create a provider from AI configuration
-`get_chat_model() -> BaseChatModel` - Get the underlying LangChain model
199
+
-`run(input, output_type=None) -> RunnerResult` — Run the agent with the given input. Returns `RunnerResult` with `content`, `metrics` (including `tool_calls`), and `raw`.
200
+
-`get_agent() -> Any` — Return the underlying compiled agent graph.
0 commit comments