Skip to content

Commit

Permalink
Add support for Anthropic Claude 3.5
Browse files Browse the repository at this point in the history
  • Loading branch information
feiskyer committed Jul 2, 2024
1 parent c7489df commit d3b9118
Show file tree
Hide file tree
Showing 8 changed files with 1,802 additions and 1,226 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## v4.4.4

* Add support for Anthropic Claude 3.5

## v4.4.3

* Support GPT-4o
Expand Down
18 changes: 12 additions & 6 deletions media/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -460,31 +460,37 @@
});

$(function () {
var availableCommands = ["/clear"];
const availableCommands = ["/clear", "/settings"];

$("#question-input").autocomplete({
source: function (request, response) {
if (request.term.startsWith("/")) {
var filteredCommands = availableCommands.filter(function (command) {
return command.startsWith(request.term);
});
response(filteredCommands);
response(availableCommands.filter(command => command.startsWith(request.term)));
} else {
response([]);
}
},
position: { my: "right bottom", at: "right top" },
position: { my: "left bottom", at: "left top" },
delay: 10,
open: function () {
$(this).data("ui-autocomplete").menu.focus(null, $(".ui-menu-item").first());
},
select: function (event, ui) {
if (ui.item.value === "/clear") {
clearConversation();
}

if (ui.item.value === "/settings") {
vscode.postMessage({
type: "openSettings",
});
}

$('#question-input').val("");
return false;
}
});

});

})();
48 changes: 27 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
"displayName": "ChatGPT Copilot",
"icon": "images/ai-logo.png",
"description": "An VS Code ChatGPT Copilot Extension",
"version": "4.4.3",
"version": "4.4.4",
"aiKey": "",
"repository": {
"url": "https://github.com/feiskyer/chatgpt-copilot"
},
"engines": {
"vscode": "^1.85.0"
"vscode": "^1.90.0"
},
"categories": [
"Testing",
Expand Down Expand Up @@ -417,6 +417,7 @@
"claude-3-opus-20240229",
"claude-3-sonnet-20240229",
"claude-3-haiku-20240307",
"claude-3-5-sonnet-20240620",
"custom"
],
"default": "gpt-3.5-turbo",
Expand Down Expand Up @@ -451,6 +452,7 @@
"Claude 3 - claude-3-opus-20240229",
"Claude 3 - claude-3-sonnet-20240229",
"Claude 3 - claude-3-haiku-20240307",
"Claude 3 - claude-3-5-sonnet-20240620",
"Custom Model"
],
"markdownEnumDescriptions": [
Expand Down Expand Up @@ -482,6 +484,7 @@
"claude-3-opus-20240229",
"claude-3-sonnet-20240229",
"claude-3-haiku-20240307",
"claude-3-5-sonnet-20240620",
"Custom model name set by `chatgpt.gpt3.customModel`"
]
},
Expand Down Expand Up @@ -558,53 +561,56 @@
"fmt": "prettier --write \"src/**/*.ts\"&& yarn run test",
"update": "npm install -g npm-check-updates && ncu -u && npm install",
"test": "eslint src --ext ts && tsc --noEmit",
"package": "vsce package --yarn",
"publish": "vsce publish --yarn"
"package": "npx @vscode/vsce package --yarn",
"publish": "npx @vscode/vsce publish --yarn"
},
"devDependencies": {
"@types/glob": "^8.1.0",
"@types/isomorphic-fetch": "^0.0.39",
"@types/mocha": "^10.0.6",
"@types/mocha": "^10.0.7",
"@types/node": "^20.14.9",
"@types/uuid": "^9.0.8",
"@types/vscode": "^1.85.0",
"@types/uuid": "^10.0.0",
"@types/vscode": "^1.90.0",
"@types/vscode-webview": "^1.57.5",
"@typescript-eslint/eslint-plugin": "^7.11.0",
"@typescript-eslint/eslint-plugin": "^7.14.1",
"@typescript-eslint/parser": "^7.14.1",
"@vscode/test-electron": "^2.4.0",
"@vscode/vsce": "^2.24.0",
"esbuild": "^0.20.1",
"eslint": "^8.56.0",
"glob": "^10.3.10",
"mocha": "^10.3.0",
"@vscode/vsce": "^2.29.0",
"esbuild": "^0.21.5",
"eslint": "^9.6.0",
"glob": "^10.4.2",
"mocha": "^10.5.2",
"prettier": "^3.3.2",
"ts-loader": "^9.5.1",
"typescript": "^5.5.2",
"webpack": "^5.90.3"
"webpack": "^5.92.1"
},
"dependencies": {
"@langchain/anthropic": "^0.1.10",
"@langchain/anthropic": "^0.2.3",
"@langchain/community": "^0.2.16",
"@langchain/openai": "^0.2.1",
"@types/minimatch": "^5.1.2",
"axios": "^1.6.7",
"axios": "^1.7.2",
"cheerio": "^1.0.0-rc.12",
"delay": "^6.0.0",
"eventsource-parser": "^1.1.2",
"gpt3-tokenizer": "^1.1.5",
"isomorphic-fetch": "^3.0.0",
"keyv": "^4.5.4",
"langchain": "^0.1.31",
"minimatch": "^5.1.6",
"openai": "^4.28.0",
"langchain": "^0.2.8",
"minimatch": "^9.0.5",
"openai": "^4.52.2",
"p-timeout": "^6.1.2",
"puppeteer": "^19.11.1",
"punycode": "^2.3.1",
"puppeteer": "^22.12.1",
"puppeteer-extra": "^3.3.6",
"puppeteer-extra-plugin-stealth": "^2.11.2",
"puppeteer-extra-plugin-user-data-dir": "^2.4.1",
"puppeteer-extra-plugin-user-preferences": "^2.4.1",
"quick-lru": "^7.0.0",
"remark": "^15.0.1",
"strip-markdown": "^6.0.0",
"uuid": "^9.0.1"
"uuid": "^10.0.0"
},
"resolutions": {
"clone-deep": "^4.0.1"
Expand Down
30 changes: 23 additions & 7 deletions src/anthropic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@
* copies or substantial portions of the Software.
*/
import { ChatAnthropic } from "@langchain/anthropic";
import { AgentAction, AgentFinish } from "@langchain/core/agents";
import { RunnableWithMessageHistory } from "@langchain/core/runnables";
import { BingSerpAPI } from "@langchain/community/tools/bingserpapi";
import { GoogleCustomSearch } from "@langchain/community/tools/google_custom_search";
import { Serper } from "@langchain/community/tools/serper";
import { AgentAction, AgentFinish, AgentStep } from "@langchain/core/agents";
import { ChatPromptTemplate as ChatPromptTemplatePackage } from "@langchain/core/prompts";
import { RunnableSequence, RunnableWithMessageHistory } from "@langchain/core/runnables";
import { Tool } from "@langchain/core/tools";
import { AgentExecutor } from "langchain/agents";
import { formatXml } from "langchain/agents/format_scratchpad/xml";
import { XMLAgentOutputParser } from "langchain/agents/xml/output_parser";
import { ChatPromptTemplate as ChatPromptTemplatePackage } from "langchain/prompts";
import { AgentStep } from "langchain/schema";
import { RunnableSequence } from "langchain/schema/runnable";
import { BingSerpAPI, GoogleCustomSearch, Serper, Tool } from "langchain/tools";
import { renderTextDescription } from "langchain/tools/render";
import ChatGptViewProvider from "./chatgpt-view-provider";
import { ModelConfig } from "./model-config";
Expand Down Expand Up @@ -53,7 +54,21 @@ export async function initClaudeModel(viewProvider: ChatGptViewProvider, config:
tools.push(new BingSerpAPI(config.bingKey));
}

const systemContext = `You are ChatGPT helping the User with coding.
let systemContext = `You are ChatGPT helping the User with coding.
You are intelligent, helpful and an expert developer, who always gives the correct answer and only does what instructed.
You always answer truthfully and don't make things up. When responding to the following prompt, please make sure to
properly style your response using Github Flavored Markdown. Use markdown syntax for things like headings, lists, colored
text, code blocks, highlights etc. Make sure not to mention markdown or styling in your actual response.
When you are done, respond with a final answer between <final_answer></final_answer>. For example:
<final_answer>The weather in SF is 64 degrees</final_answer>
Ensure the final answer is in the same language as the question, unless otherwise specified by the question.
`;

if (tools.length > 0) {
systemContext = `You are ChatGPT helping the User with coding.
You are intelligent, helpful and an expert developer, who always gives the correct answer and only does what instructed.
You always answer truthfully and don't make things up. When responding to the following prompt, please make sure to
properly style your response using Github Flavored Markdown. Use markdown syntax for things like headings, lists, colored
Expand All @@ -77,6 +92,7 @@ When you are done, respond with a final answer between <final_answer></final_ans
Ensure the final answer is in the same language as the question, unless otherwise specified by the question.
`;
}

const chatPrompt = ChatPromptTemplatePackage.fromMessages([
["human", systemContext],
Expand Down
17 changes: 7 additions & 10 deletions src/chatgpt-view-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,9 @@
* copies or substantial portions of the Software.
*/

import { RunnableWithMessageHistory } from "@langchain/core/runnables";
import { ChatOpenAI, OpenAI } from "@langchain/openai";
import delay from "delay";
import { LLMChain } from "langchain/chains";
import { ChatOpenAI } from "langchain/chat_models/openai";
import { OpenAI } from "langchain/llms/openai";
import { BufferMemory } from "langchain/memory";

import { ChainValues } from "langchain/schema";
import { ChatMessageHistory } from "langchain/stores/message/in_memory";
import { Tool } from "langchain/tools";
import * as vscode from "vscode";
Expand All @@ -41,8 +36,8 @@ export default class ChatGptViewProvider implements vscode.WebviewViewProvider {

public apiCompletion?: OpenAI;
public apiChat?: ChatOpenAI;
public chain?: RunnableWithMessageHistory<Record<string, any>, ChainValues>;
public llmChain?: LLMChain;
public chain?: any;
public llmChain?: any;
public tools?: Tool[];
public memory?: ChatMessageHistory;
public conversationId?: string;
Expand Down Expand Up @@ -680,7 +675,6 @@ export default class ChatGptViewProvider implements vscode.WebviewViewProvider {
background-color: #484a44;
color: #ffffff;
border: 1px solid #1f241f;
padding: 10px;
width: 200px;
}
Expand All @@ -691,7 +685,10 @@ export default class ChatGptViewProvider implements vscode.WebviewViewProvider {
/* Customize the item that is currently selected or being hovered over */
.ui-menu-item.ui-state-focus {
background-color: #808080;
background-color: #808080 !important;
}
.ui-menu-item .ui-menu-item-wrapper.ui-state-active {
background-color: #808080 !important;
}
</style>
Expand Down
8 changes: 4 additions & 4 deletions src/openai-legacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*/
import { ConversationChain } from "langchain/chains";
import { OpenAI } from "langchain/llms/openai";
import { BufferMemory } from "langchain/memory";
import {
ChatPromptTemplate as ChatPromptTemplatePackage,
HumanMessagePromptTemplate,
MessagesPlaceholder,
SystemMessagePromptTemplate
} from "langchain/prompts";
} from "@langchain/core/prompts";
import { OpenAI } from "@langchain/openai";
import { ConversationChain } from "langchain/chains";
import { BufferMemory } from "langchain/memory";
import ChatGptViewProvider, { logger } from "./chatgpt-view-provider";
import { ModelConfig } from "./model-config";

Expand Down
33 changes: 22 additions & 11 deletions src/openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,32 @@
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*/
import { RunnableWithMessageHistory } from "@langchain/core/runnables";
import { OpenAIEmbeddings } from "@langchain/openai";
import { AgentExecutor, createOpenAIFunctionsAgent } from "langchain/agents";
import { ChatOpenAI } from "langchain/chat_models/openai";
import { BingSerpAPI } from "@langchain/community/tools/bingserpapi";
import { GoogleCustomSearch } from "@langchain/community/tools/google_custom_search";
import { Serper } from "@langchain/community/tools/serper";
import { WikipediaQueryRun } from "@langchain/community/tools/wikipedia_query_run";
import {
ChatPromptTemplate as ChatPromptTemplatePackage,
HumanMessagePromptTemplate,
MessagesPlaceholder,
SystemMessagePromptTemplate
} from "langchain/prompts";
import { BingSerpAPI, GoogleCustomSearch, Serper, Tool } from "langchain/tools";
} from "@langchain/core/prompts";
import { RunnableWithMessageHistory } from "@langchain/core/runnables";
import { Tool } from "@langchain/core/tools";
import { ChatOpenAI, OpenAIEmbeddings } from "@langchain/openai";
import { AgentExecutor, createOpenAIFunctionsAgent } from "langchain/agents";
import { WebBrowser } from "langchain/tools/webbrowser";
import ChatGptViewProvider, { logger } from "./chatgpt-view-provider";
import { ModelConfig } from "./model-config";

// initGptModel initializes the GPT model.
export async function initGptModel(viewProvider: ChatGptViewProvider, config: ModelConfig) {
let tools: Tool[] = [];
let tools: Tool[] = [
new WikipediaQueryRun({
topKResults: 3,
maxDocContentLength: 4000,
})
];
if (config.googleCSEApiKey != "" && config.googleCSEId != "") {
tools.push(new GoogleCustomSearch({
apiKey: config.googleCSEApiKey,
Expand All @@ -46,6 +54,7 @@ export async function initGptModel(viewProvider: ChatGptViewProvider, config: Mo
modelName: "text-embedding-ada-002",
openAIApiKey: config.apiKey,
});

// AzureOpenAI
if (config.apiBaseUrl?.includes("azure")) {
const instanceName = config.apiBaseUrl.split(".")[0].split("//")[1];
Expand Down Expand Up @@ -87,10 +96,12 @@ export async function initGptModel(viewProvider: ChatGptViewProvider, config: Mo
});
}

tools.push(new WebBrowser({
model: viewProvider.apiChat,
embeddings: embeddings,
}));
if (config.apiBaseUrl == "https://api.openai.com/v1") {
tools.push(new WebBrowser({
model: viewProvider.apiChat,
embeddings: embeddings,
}));
}

const systemContext = `Your task is to embody the role of an intelligent, helpful, and expert developer.
You MUST provide accurate and truthful answers, adhering strictly to the instructions given.
Expand Down
Loading

0 comments on commit d3b9118

Please sign in to comment.