-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from luveqz/2024-03-05-add-anthropic-provider
[feature] add anthropic provider
- Loading branch information
Showing
22 changed files
with
3,624 additions
and
1,191 deletions.
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 |
---|---|---|
|
@@ -29,4 +29,5 @@ results | |
yarn.lock | ||
|
||
# Secrets | ||
browserstack.json | ||
browserstack.json | ||
.vercel |
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,48 @@ | ||
import Anthropic from '@anthropic-ai/sdk' | ||
import express from 'express' | ||
import cors from 'cors' | ||
const app = express() | ||
const port = 3001 | ||
|
||
app.use(cors()) | ||
app.use(express.json()) | ||
|
||
app.post('/api/generate', async (req, res) => { | ||
const apiKey = req.body.apiKey | ||
const prompt = req.body.prompt | ||
const model = req.body.model | ||
|
||
const anthropic = new Anthropic({ | ||
apiKey, | ||
}) | ||
|
||
const stream = await anthropic.messages.create({ | ||
max_tokens: 1024, | ||
messages: [ | ||
{ | ||
role: 'user', | ||
content: prompt, | ||
}, | ||
], | ||
model, | ||
stream: true, | ||
}) | ||
|
||
for await (const messageStreamEvent of stream) { | ||
if (messageStreamEvent?.delta?.text) { | ||
res.write(messageStreamEvent?.delta?.text) | ||
} | ||
} | ||
|
||
res.end() | ||
}) | ||
|
||
app.listen(port, () => { | ||
console.log('[*] Anthropic endpoint running') | ||
}) | ||
|
||
export default app | ||
|
||
export const config = { | ||
supportsResponseStreaming: true, | ||
} |
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
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,101 @@ | ||
<template> | ||
<section class="p-10 px-14"> | ||
<h2 class="text-2xl font-bold">Models</h2> | ||
|
||
<p class="mt-4 leading-[120%]"> | ||
You can connect <strong>Dear Ghost</strong> to different large language | ||
model providers. These are all the supported ones: | ||
</p> | ||
</section> | ||
|
||
<hr class="border-0 border-b-2 border-[#DEE4EB]" /> | ||
|
||
<section class="p-10 px-14"> | ||
<h3 class="text-xl font-bold"> Anthropic </h3> | ||
|
||
<p class="mt-4 leading-[120%]"> | ||
The company behind <strong>Claude</strong>, one of the most popular family | ||
of models within the creative writing space. | ||
</p> | ||
<p class="mt-4 leading-[120%]"> | ||
To use Claude through the Dear Ghost interface, you will have to create an | ||
API key on the | ||
<a | ||
class="font-semibold text-blue-600" | ||
href="https://console.anthropic.com/dashboard" | ||
target="_blank" | ||
rel="noreferrer" | ||
>Anthropic Console</a | ||
>. | ||
</p> | ||
|
||
<label class="mb-1 mt-5 block font-bold">API key:</label> | ||
<BaseInput | ||
variant="medium" | ||
v-model="$editor.providerConfig.anthropic.apiKey" | ||
class="w-full max-w-72" | ||
placeholder="sk-ant-api03-rV97zpCN..." | ||
/> | ||
</section> | ||
|
||
<hr class="mx-auto max-w-20 border-0 border-b-2 border-[#DEE4EB]" /> | ||
|
||
<section class="p-10 px-14"> | ||
<h3 class="text-xl font-bold"> LM Studio </h3> | ||
|
||
<p class="mt-4 leading-[120%]"> | ||
This is an app you can use to download and run models on your laptop. | ||
<strong>Mistral 7B</strong> | ||
is one of the many models in their catalog. | ||
</p> | ||
<p class="mt-4 leading-[120%]"> | ||
Once you have installed | ||
<a | ||
class="font-semibold text-blue-600" | ||
href="https://lmstudio.ai/" | ||
target="_blank" | ||
rel="noreferrer" | ||
>LM Studio</a | ||
>. and downloaded your favorite model, run its local server. | ||
</p> | ||
|
||
<label class="mb-1 mt-5 block font-bold">Server port:</label> | ||
<BaseInput | ||
variant="medium" | ||
v-model="$editor.providerConfig.lmStudio.port" | ||
class="w-full max-w-72" | ||
placeholder="4321" | ||
/> | ||
</section> | ||
|
||
<hr class="mx-auto max-w-20 border-0 border-b-2 border-[#DEE4EB]" /> | ||
|
||
<section class="p-10 px-14 pb-20"> | ||
<h3 class="text-xl font-bold"> Ollama </h3> | ||
|
||
<p class="mt-4 leading-[120%]"> | ||
A command-line tool you can use to download and run models on your laptop. | ||
<strong>Mistral 7B</strong> | ||
is one of the many models in their catalog. | ||
</p> | ||
<p class="mt-4 leading-[120%]"> | ||
Once you have installed | ||
<a | ||
class="font-semibold text-blue-600" | ||
href="https://ollama.com/" | ||
target="_blank" | ||
rel="noreferrer" | ||
>Ollama</a | ||
> | ||
and downloaded your favorite model, run its local server. | ||
</p> | ||
|
||
<label class="mb-1 mt-5 block font-bold">Server host:</label> | ||
<BaseInput | ||
variant="medium" | ||
v-model="$editor.providerConfig.ollama.host" | ||
class="w-full max-w-72" | ||
placeholder="http://localhost:11434" | ||
/> | ||
</section> | ||
</template> |
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,17 @@ | ||
<template> | ||
<div class="mt-52 flex flex-col items-center"> | ||
<HeartIcon class="h-6 w-6 text-orange-500" /> | ||
|
||
<p class="mx-6 mt-3 max-w-60 text-center leading-tight"> | ||
Become a | ||
<a | ||
class="font-bold text-orange-600" | ||
href="https://www.patreon.com/DearGhost" | ||
target="_blank" | ||
rel="noreferrer" | ||
>Patreon</a | ||
> | ||
and help make this possible. | ||
</p> | ||
</div> | ||
</template> |
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 @@ | ||
<script setup> | ||
import { TabGroup, TabList, Tab, TabPanels, TabPanel } from '@headlessui/vue' | ||
const tabs = ['Models', 'Prompts', 'Appearance'] | ||
</script> | ||
|
||
<template> | ||
<div | ||
class="flex h-[calc(100vh_-_8rem)] w-full max-w-[48rem] overflow-hidden rounded bg-white font-normal" | ||
> | ||
<TabGroup> | ||
<TabList | ||
class="flex w-40 shrink-0 flex-col items-start gap-y-5 bg-[#DEE4EB] px-9 py-12" | ||
> | ||
<Tab v-for="tab in tabs" :key="tab" v-slot="{ selected }"> | ||
<span :class="{ 'font-bold': selected }"> | ||
{{ tab }} | ||
</span> | ||
</Tab> | ||
</TabList> | ||
|
||
<TabPanels class="mr-2 grow overflow-y-auto"> | ||
<TabPanel> | ||
<ModelConfigPanel /> | ||
</TabPanel> | ||
|
||
<TabPanel> | ||
<PatreonConfigPanel /> | ||
</TabPanel> | ||
|
||
<TabPanel> | ||
<PatreonConfigPanel /> | ||
</TabPanel> | ||
</TabPanels> | ||
</TabGroup> | ||
</div> | ||
</template> |
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
Oops, something went wrong.