Skip to content

Commit

Permalink
feat: ThreadActions.getModelConfig (#870)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yonom authored Sep 22, 2024
1 parent 155d6e7 commit f80226f
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 6 deletions.
6 changes: 6 additions & 0 deletions .changeset/fuzzy-ladybugs-reply.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@assistant-ui/react": patch
"@assistant-ui/react-playground": patch
---

feat: ThreadActions.getModelConfig
4 changes: 4 additions & 0 deletions packages/react-playground/src/lib/playground-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ export class PlaygroundThreadRuntime implements ReactThreadRuntime {
});
}

public getModelConfig() {
return this.configProvider.getModelConfig();
}

public setRequestData({
apiKey,
baseUrl,
Expand Down
5 changes: 5 additions & 0 deletions packages/react/src/context/stores/ThreadActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { AppendMessage } from "../../types/AssistantTypes";
import { ReadonlyStore } from "../ReadonlyStore";
import { ThreadRuntimeStore } from "./ThreadRuntime";
import { SpeechSynthesisAdapter } from "../../runtimes/speech/SpeechAdapterTypes";
import { ModelConfig } from "../../types";

export type AddToolResultOptions = {
messageId: string;
Expand All @@ -29,6 +30,8 @@ export type ThreadActionsState = Readonly<{
speak: (messageId: string) => SpeechSynthesisAdapter.Utterance;

submitFeedback: (feedback: SubmitFeedbackOptions) => void;

getModelConfig: () => ModelConfig;
}>;

export const makeThreadActionStore = (
Expand All @@ -52,6 +55,8 @@ export const makeThreadActionStore = (

submitFeedback: ({ messageId, type }) =>
runtimeStore.getState().submitFeedback({ messageId, type }),

getModelConfig: () => runtimeStore.getState().getModelConfig(),
}),
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import { ExternalStoreAdapter } from "./ExternalStoreAdapter";
import { ExternalStoreThreadRuntime } from "./ExternalStoreThreadRuntime";

export class ExternalStoreRuntime extends BaseAssistantRuntime<ExternalStoreThreadRuntime> {
private readonly _proxyConfigProvider = new ProxyConfigProvider();
private readonly _proxyConfigProvider;

constructor(store: ExternalStoreAdapter<any>) {
super(new ExternalStoreThreadRuntime(store));
const provider = new ProxyConfigProvider();
super(new ExternalStoreThreadRuntime(provider, store));
this._proxyConfigProvider = provider;
}

public get store() {
Expand All @@ -30,7 +32,7 @@ export class ExternalStoreRuntime extends BaseAssistantRuntime<ExternalStoreThre
if (!this.store.onSwitchToNewThread)
throw new Error("Runtime does not support switching to new threads.");

this.thread = new ExternalStoreThreadRuntime({
this.thread = new ExternalStoreThreadRuntime(this._proxyConfigProvider, {
...this.store,
messages: [],
});
Expand All @@ -42,7 +44,7 @@ export class ExternalStoreRuntime extends BaseAssistantRuntime<ExternalStoreThre
if (!this.store.onSwitchToThread)
throw new Error("Runtime does not support switching threads.");

this.thread = new ExternalStoreThreadRuntime({
this.thread = new ExternalStoreThreadRuntime(this._proxyConfigProvider, {
...this.store,
messages: [], // ignore messages until rerender
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { ReactThreadRuntime } from "../core";
import { MessageRepository } from "../utils/MessageRepository";
import { AppendMessage, ThreadMessage, Unsubscribe } from "../../types";
import {
AppendMessage,
ModelConfigProvider,
ThreadMessage,
Unsubscribe,
} from "../../types";
import { ExternalStoreAdapter } from "./ExternalStoreAdapter";
import { AddToolResultOptions } from "../../context";
import {
Expand Down Expand Up @@ -55,7 +60,10 @@ export class ExternalStoreThreadRuntime implements ReactThreadRuntime {
this.notifySubscribers.bind(this),
);

constructor(store: ExternalStoreAdapter<any>) {
constructor(
private configProvider: ModelConfigProvider,
store: ExternalStoreAdapter<any>,
) {
this.store = store;
}

Expand Down Expand Up @@ -153,6 +161,10 @@ export class ExternalStoreThreadRuntime implements ReactThreadRuntime {
this.notifySubscribers();
}

public getModelConfig() {
return this.configProvider.getModelConfig();
}

private notifySubscribers() {
for (const callback of this._subscriptions) callback();
}
Expand Down
4 changes: 4 additions & 0 deletions packages/react/src/runtimes/local/LocalThreadRuntime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ export class LocalThreadRuntime implements ThreadRuntime {
}
}

public getModelConfig() {
return this.configProvider.getModelConfig();
}

private _options!: LocalRuntimeOptions;

public get options() {
Expand Down

0 comments on commit f80226f

Please sign in to comment.