-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(similarity): add sentence similarity service
Signed-off-by: Tomas Pilar <[email protected]>
- Loading branch information
Tomas Pilar
committed
Jun 19, 2024
1 parent
bd36c38
commit d159617
Showing
6 changed files
with
75 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export const MODEL = 'google/flan-ul2'; | ||
export const CHAT_MODEL = 'meta-llama/llama-3-70b-instruct'; | ||
export const EMBEDDING_MODEL = 'sentence-transformers/all-minilm-l6-v2'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Client } from '../src/index.js'; | ||
|
||
import { EMBEDDING_MODEL } from './shared/constants.js'; | ||
|
||
const client = new Client({ | ||
apiKey: process.env.GENAI_API_KEY, | ||
}); | ||
|
||
{ | ||
const output = await client.text.experimental.sentenceSimilarity.create({ | ||
model_id: EMBEDDING_MODEL, | ||
source_sentence: 'Good morning', | ||
sentences: ['How are you?', 'Get lost!'], | ||
}); | ||
console.log(output); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { Options } from '../../client.js'; | ||
import { clientErrorWrapper } from '../../utils/errors.js'; | ||
import { | ||
TextSentenceSimilarityCreateInput, | ||
TextSentenceSimilarityCreateOutput, | ||
} from '../../schema.js'; | ||
import { ApiClient } from '../../api/client.js'; | ||
import { SteamingApiClient } from '../../api/streaming-client.js'; | ||
import { ConcurrencyLimiter } from '../../utils/concurrency.js'; | ||
import { BaseService } from '../BaseService.js'; | ||
|
||
export class TextSentenceSimilarityService extends BaseService { | ||
constructor( | ||
protected readonly _client: ApiClient, | ||
protected readonly _streamingClient: SteamingApiClient, | ||
protected readonly _limiter: ConcurrencyLimiter, | ||
) { | ||
super(_client, _streamingClient); | ||
} | ||
|
||
create( | ||
input: TextSentenceSimilarityCreateInput, | ||
opts?: Options, | ||
): Promise<TextSentenceSimilarityCreateOutput> { | ||
return this._limiter.execute( | ||
() => | ||
clientErrorWrapper( | ||
this._client.POST('/v2/beta/text/sentence-similarity', { | ||
...opts, | ||
params: { query: { version: '2023-11-22' } }, | ||
body: input, | ||
}), | ||
), | ||
{ signal: opts?.signal }, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters