mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-01 17:39:39 +02:00
refactor(ts): remove non-client effect run boundaries
This commit is contained in:
parent
be2370ee7b
commit
174d636178
20 changed files with 126 additions and 106 deletions
|
|
@ -176,7 +176,22 @@ const makeAzureOpenAIProviderFromClient = (
|
|||
export function makeAzureOpenAIProvider(
|
||||
config: AzureOpenAIProcessorConfig,
|
||||
): LlmProvider<TextCompletionRuntimeError> {
|
||||
return Effect.runSync(makeAzureOpenAIProviderEffect(config));
|
||||
const resolved = {
|
||||
defaultModel: config.model ?? "gpt-4o",
|
||||
defaultTemperature: config.temperature ?? 0.0,
|
||||
maxOutput: config.maxOutput ?? 4096,
|
||||
apiKey: config.apiKey ?? "",
|
||||
endpoint: config.endpoint ?? "",
|
||||
apiVersion: config.apiVersion ?? "2024-12-01-preview",
|
||||
} satisfies ResolvedAzureOpenAIConfig;
|
||||
return makeAzureOpenAIProviderFromClient(
|
||||
resolved,
|
||||
new AzureOpenAI({
|
||||
apiKey: resolved.apiKey,
|
||||
apiVersion: resolved.apiVersion,
|
||||
endpoint: resolved.endpoint,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export const makeAzureOpenAIProviderEffect = Effect.fn("makeAzureOpenAIProvider")(function*(
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ import {
|
|||
makeFlowProcessorProgram,
|
||||
makeLlmSpecs,
|
||||
} from "@trustgraph/base";
|
||||
import { Effect, Layer, Redacted } from "effect";
|
||||
import { Context, Effect, Layer, Redacted } from "effect";
|
||||
import { FetchHttpClient } from "effect/unstable/http";
|
||||
import type {
|
||||
TextCompletionConfigError,
|
||||
|
|
@ -69,7 +69,32 @@ const makeClaudeLayer = (apiKey: string) =>
|
|||
export function makeClaudeProvider(
|
||||
config: ClaudeProcessorConfig,
|
||||
): LlmProvider<TextCompletionRuntimeError> {
|
||||
return Effect.runSync(Effect.scoped(makeClaudeProviderEffect(config)));
|
||||
const resolved = {
|
||||
defaultModel: config.model ?? "claude-sonnet-4-20250514",
|
||||
defaultTemperature: config.temperature ?? 0.0,
|
||||
maxOutput: config.maxOutput ?? 8192,
|
||||
apiKey: config.apiKey ?? "",
|
||||
} satisfies ResolvedClaudeConfig;
|
||||
return makeLanguageModelProvider({
|
||||
provider: "Claude",
|
||||
defaultModel: resolved.defaultModel,
|
||||
defaultTemperature: resolved.defaultTemperature,
|
||||
context: Context.empty(),
|
||||
makeLanguageModel: ({ model, temperature }) =>
|
||||
Effect.scoped(
|
||||
Layer.build(makeClaudeLayer(resolved.apiKey)).pipe(
|
||||
Effect.flatMap((context) =>
|
||||
AnthropicLanguageModel.make({
|
||||
model,
|
||||
config: {
|
||||
max_tokens: resolved.maxOutput,
|
||||
temperature,
|
||||
},
|
||||
}).pipe(Effect.provideContext(context))
|
||||
),
|
||||
),
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
export const makeClaudeProviderEffect = Effect.fn("makeClaudeProvider")(function* (
|
||||
|
|
|
|||
|
|
@ -156,7 +156,16 @@ const makeMistralProviderFromClient = (
|
|||
export function makeMistralProvider(
|
||||
config: MistralProcessorConfig,
|
||||
): LlmProvider<TextCompletionRuntimeError> {
|
||||
return Effect.runSync(makeMistralProviderEffect(config));
|
||||
const resolved = {
|
||||
defaultModel: config.model ?? "ministral-8b-latest",
|
||||
defaultTemperature: config.temperature ?? 0.0,
|
||||
maxOutput: config.maxOutput ?? 4096,
|
||||
apiKey: config.apiKey ?? "",
|
||||
} satisfies ResolvedMistralConfig;
|
||||
return makeMistralProviderFromClient(
|
||||
resolved,
|
||||
new Mistral({ apiKey: resolved.apiKey }),
|
||||
);
|
||||
}
|
||||
|
||||
export const makeMistralProviderEffect = Effect.fn("makeMistralProvider")(function*(
|
||||
|
|
|
|||
|
|
@ -132,7 +132,14 @@ const makeOllamaProviderFromClient = (
|
|||
export function makeOllamaProvider(
|
||||
config: OllamaProcessorConfig,
|
||||
): LlmProvider<TextCompletionRuntimeError> {
|
||||
return Effect.runSync(makeOllamaProviderEffect(config));
|
||||
const resolved = {
|
||||
defaultModel: config.model ?? "qwen2.5:0.5b",
|
||||
host: config.ollamaUrl ?? "http://localhost:11434",
|
||||
} satisfies ResolvedOllamaConfig;
|
||||
return makeOllamaProviderFromClient(
|
||||
resolved,
|
||||
new Ollama({ host: resolved.host }),
|
||||
);
|
||||
}
|
||||
|
||||
export const makeOllamaProviderEffect = Effect.fn("makeOllamaProvider")(function*(
|
||||
|
|
|
|||
|
|
@ -165,7 +165,17 @@ const makeOpenAICompatibleProviderFromClient = (
|
|||
export function makeOpenAICompatibleProvider(
|
||||
config: OpenAICompatibleProcessorConfig,
|
||||
): LlmProvider<TextCompletionRuntimeError> {
|
||||
return Effect.runSync(makeOpenAICompatibleProviderEffect(config));
|
||||
const resolved = {
|
||||
defaultModel: config.model ?? "default",
|
||||
defaultTemperature: config.temperature ?? 0.0,
|
||||
maxOutput: config.maxOutput ?? 4096,
|
||||
apiKey: config.apiKey ?? "sk-no-key-required",
|
||||
baseURL: config.baseUrl ?? "http://localhost:1234/v1",
|
||||
} satisfies ResolvedOpenAICompatibleConfig;
|
||||
return makeOpenAICompatibleProviderFromClient(
|
||||
resolved,
|
||||
new OpenAI({ baseURL: resolved.baseURL, apiKey: resolved.apiKey }),
|
||||
);
|
||||
}
|
||||
|
||||
export const makeOpenAICompatibleProviderEffect = Effect.fn("makeOpenAICompatibleProvider")(function*(
|
||||
|
|
|
|||
|
|
@ -155,7 +155,20 @@ const makeOpenAIProviderFromClient = (
|
|||
export function makeOpenAIProvider(
|
||||
config: OpenAIProcessorConfig,
|
||||
): LlmProvider<TextCompletionRuntimeError> {
|
||||
return Effect.runSync(makeOpenAIProviderEffect(config));
|
||||
const resolved = {
|
||||
defaultModel: config.model ?? "gpt-4o",
|
||||
defaultTemperature: config.temperature ?? 0.0,
|
||||
maxOutput: config.maxOutput ?? 4096,
|
||||
apiKey: config.apiKey ?? "",
|
||||
baseURL: config.baseUrl,
|
||||
} satisfies ResolvedOpenAIConfig;
|
||||
return makeOpenAIProviderFromClient(
|
||||
resolved,
|
||||
new OpenAI({
|
||||
apiKey: resolved.apiKey,
|
||||
baseURL: resolved.baseURL,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export const makeOpenAIProviderEffect = Effect.fn("makeOpenAIProvider")(function*(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue