Skip to content

Commit

Permalink
change visibility, naming, docs
Browse files Browse the repository at this point in the history
  • Loading branch information
tomfrenken committed Sep 16, 2024
1 parent 21907d1 commit e64243e
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion packages/ai-api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ export type {
DeploymentIdConfiguration,
ModelConfiguration,
ResourceGroupConfiguration,
ConfigurationOptions
ModelDeploymentConfig
} from './utils/index.js';
4 changes: 2 additions & 2 deletions packages/ai-api/src/utils/deployment-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ export interface ResourceGroupConfiguration {
*/
export type ModelDeployment<ModelNameT = string> =
| ModelNameT
| ConfigurationOptions<ModelNameT>;
| ModelDeploymentConfig<ModelNameT>;

/**
* The configuration options for a model deployment.
* @typeParam ModelNameT - String literal type representing the name of the model.
*/
export type ConfigurationOptions<ModelNameT> = Xor<
export type ModelDeploymentConfig<ModelNameT> = Xor<
ModelConfiguration<ModelNameT>,
DeploymentIdConfiguration
> &
Expand Down
8 changes: 4 additions & 4 deletions packages/langchain/src/openai/embedding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ export class AzureOpenAiEmbeddingClient extends AzureOpenAIEmbeddings {
);
const embeddings: number[][] = [];
for await (const promptChunk of chunkedPrompts) {
const resArr = await this.createEmbedding({ input: promptChunk });
resArr.data.forEach(res => embeddings.push(res.embedding));
const embeddingResponse = await this.createEmbedding({ input: promptChunk });
embeddingResponse.data.forEach(entry => embeddings.push(entry.embedding));
}
return embeddings;
}

override async embedQuery(query: string): Promise<number[]> {
const resArr = await this.createEmbedding({
const embeddingResponse = await this.createEmbedding({
input: this.stripNewLines ? query.replace(/\n/g, ' ') : query
});
return resArr.data[0].embedding;
return embeddingResponse.data[0].embedding;
}

private async createEmbedding(
Expand Down
6 changes: 3 additions & 3 deletions packages/langchain/src/openai/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type {
AzureOpenAiChatModel,
AzureOpenAiEmbeddingModel
} from '@sap-ai-sdk/core';
import type { ConfigurationOptions } from '@sap-ai-sdk/ai-api';
import type { ModelDeploymentConfig } from '@sap-ai-sdk/ai-api';

/**
* Input type for OpenAI Chat models.
Expand All @@ -33,7 +33,7 @@ export type OpenAiChatModelInput = Omit<
> &
Omit<OpenAiChatCompletionParameters, 'messages'> &
BaseChatModelParams &
ConfigurationOptions<AzureOpenAiChatModel>;
ModelDeploymentConfig<AzureOpenAiChatModel>;

/**
* Chat model call options for OpenAI.
Expand All @@ -60,5 +60,5 @@ export type OpenAiEmbeddingInput = Omit<
OpenAIEmbeddingsParams,
'modelName' | 'model' | 'azureOpenAIApiKey' | 'apiKey'
> &
ConfigurationOptions<AzureOpenAiEmbeddingModel> &
ModelDeploymentConfig<AzureOpenAiEmbeddingModel> &
BaseLLMParams;
3 changes: 0 additions & 3 deletions packages/langchain/src/openai/util.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// mapResponseToChatResult
// mapLangchainToAiClient

import {
OpenAiChatClient as OpenAiChatClientBase,
OpenAiChatCompletionOutput
Expand Down
1 change: 1 addition & 0 deletions packages/langchain/src/openai/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ export function mapBaseMessageToOpenAiChatMessage(
* Converts a value to an array or returns undefined.
* @param value - The value to convert.
* @returns The value as an array, undefined if the input is falsy, or the original array if input is already an array.
* @internal
*/
export function toArrayOrUndefined<T>(value?: T | T[]): T[] | undefined {
if (value === undefined) {
Expand Down
10 changes: 6 additions & 4 deletions sample-code/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ app.get('/embedding', async (req, res) => {
try {
const result = await computeEmbedding();
if (!result.length) {
throw new Error('No embedding vector returned');
res.status(500).send('No embedding vector returned.');
} else {
res.send('Number crunching success, got a nice vector.');
}
res.send('Number crunching success, got a nice vector.');
} catch (error: any) {
console.error(error);
res
Expand Down Expand Up @@ -78,9 +79,10 @@ app.get('/langchain/embedding', async (req, res) => {
try {
const result = await embedQuery();
if (!result.length) {
throw new Error('No embedding vector returned');
res.status(500).send('No embedding vector returned.');
} else {
res.send('Number crunching success, got a nice vector.');
}
res.send('Number crunching success, got a nice vector.');
} catch (error: any) {
console.error(error);
res
Expand Down

0 comments on commit e64243e

Please sign in to comment.