Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/models/cohere.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ export enum CohereModelType {
XLarge = "xlarge",
}

// To support the latest cohere version, see https://docs.cohere.com/reference/versioning
export enum CohereVersionEnum {
'2021-11-08' = '2021-11-08',
'2022-12-06' = '2022-12-06',
}

export interface CohereSettings {
modelType: CohereModelType;
maxTokens: number;
Expand All @@ -17,6 +23,7 @@ export interface CohereSettings {
presencePenalty: number;
frequencyPenalty: number;
stopSequences: string[];
version: CohereVersionEnum;
}

export const defaultCohereSettings: CohereSettings = {
Expand All @@ -28,6 +35,7 @@ export const defaultCohereSettings: CohereSettings = {
presencePenalty: 0,
frequencyPenalty: 0,
stopSequences: [],
version: CohereVersionEnum['2021-11-08'],
};

export const getCohereCompletion = async (
Expand All @@ -39,7 +47,7 @@ export const getCohereCompletion = async (
const headers = {
Authorization: `Bearer ${apiKey}`,
"Content-Type": "application/json",
"Cohere-Version": "2021-11-08",
"Cohere-Version": settings.version,
};
const { modelType, ...params } = settings;
let body = {
Expand Down
21 changes: 19 additions & 2 deletions src/ui/CohereSettingsForm.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from "react";
import StopSequenceInput from "src/ui/StopSequenceInput";

import { CohereModelType } from "../models/cohere";
import { CohereModelType, CohereVersionEnum } from "../models/cohere";
import GPTPlugin from "../../main";

const CohereSettingsForm = ({ plugin }: { plugin: GPTPlugin }) => {
Expand All @@ -10,7 +10,9 @@ const CohereSettingsForm = ({ plugin }: { plugin: GPTPlugin }) => {

const handleInputChange = async (e: any) => {
let { name, value } = e.target;
if (parseFloat(value) || value === "0") {
if (e.target.id !== 'version' // Do not parse version
&& (parseFloat(value) || value === "0")
) {
value = parseFloat(value);
}
setState((prevState) => ({
Expand Down Expand Up @@ -118,6 +120,21 @@ const CohereSettingsForm = ({ plugin }: { plugin: GPTPlugin }) => {
stopSequences={state.stopSequences}
onChange={onStopSequenceChange}
/>
<label htmlFor="version">Version:</label>
<select
name="version"
id="version"
value={state.version}
onChange={handleInputChange}
>
{
Object.keys(CohereVersionEnum).map((key: CohereVersionEnum) => {
const value = CohereVersionEnum[key];
return <option key={key} value={value}>{value}</option>
})
}
</select>
<br />
</form>
);
};
Expand Down