mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-01 09:29:38 +02:00
Make text completion provider layers effectful
This commit is contained in:
parent
36f629b341
commit
fe4f5777c9
9 changed files with 393 additions and 116 deletions
|
|
@ -1,9 +1,12 @@
|
|||
import {
|
||||
Llm,
|
||||
TooManyRequestsError,
|
||||
errorMessage,
|
||||
makeLlmServiceShape,
|
||||
type LlmChunk,
|
||||
type LlmProvider,
|
||||
} from "@trustgraph/base";
|
||||
import { Config, Effect, Ref, Result, Stream } from "effect";
|
||||
import { Config, Effect, Layer, Ref, Result, Stream } from "effect";
|
||||
import * as O from "effect/Option";
|
||||
import * as Predicate from "effect/Predicate";
|
||||
import * as S from "effect/Schema";
|
||||
|
|
@ -29,6 +32,17 @@ export type TextCompletionRuntimeError =
|
|||
| TextCompletionProviderError
|
||||
| TooManyRequestsError;
|
||||
|
||||
export const makeTextCompletionLayer = <E, R>(
|
||||
provider: Effect.Effect<LlmProvider, E, R>,
|
||||
): Layer.Layer<Llm, E, R> =>
|
||||
Layer.effect(Llm)(
|
||||
provider.pipe(
|
||||
Effect.map((resolvedProvider) =>
|
||||
Llm.of(makeLlmServiceShape(resolvedProvider))
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
type StreamingTokenTotals = {
|
||||
readonly inToken: number;
|
||||
readonly outToken: number;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue