Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ai assistclaude #656

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
24 changes: 24 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
},
"homepage": "https://github.com/vizhub-core/vzcode#readme",
"dependencies": {
"@anthropic-ai/sdk": "^0.20.2",
"@codemirror/autocomplete": "^6.15.0",
"@codemirror/lang-css": "^6.2.1",
"@codemirror/lang-html": "^6.4.8",
Expand Down
30 changes: 12 additions & 18 deletions src/client/AIAssist/startAIAssist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
import { TabState } from '../vzReducer';
import { RequestId } from '../generateRequestId';
import { formatFile } from './formatFile';
import Anthropic from '@anthropic-ai/sdk';

const debug = false;

Expand Down Expand Up @@ -95,26 +96,19 @@ export const startAIAssist = async ({
// );
}

const response = await fetch(aiAssistEndpoint, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
...aiAssistOptions,
inputText,
fileId,
insertionCursor,
aiStreamId,
}),
const anthropic = new Anthropic({
apiKey: 'THE_API_KEY',
});

const responseJson = await response.json();
try {
const response = await anthropic.completions.create({
model: 'claude-3',
max_tokens_to_sample: 1024,
prompt: `${Anthropic.HUMAN_PROMPT} ${inputText}${Anthropic.AI_PROMPT}`,
});

if (responseJson.error) {
console.error(
'[startAIAssist] error from server:',
responseJson.error,
);
console.log('Completion:', response.completion);
} catch (error) {
console.error('[startAIAssist] error:', error);
}
};