-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
856 additions
and
365 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 |
---|---|---|
|
@@ -13,9 +13,12 @@ | |
], | ||
"skeet-ai": [ | ||
"skeet-ai" | ||
], | ||
"skeet-cloud-task": [ | ||
"skeet-cloud-task" | ||
] | ||
} | ||
} | ||
}, | ||
"etags": {} | ||
} | ||
} |
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,41 @@ | ||
name: skeet-cloud-task | ||
on: | ||
push: | ||
branches: | ||
- main | ||
paths: | ||
- 'packages/cloud-task/docs/**' | ||
- '.github/workflows/website-skeet-cloud-task.yml' | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-22.04 | ||
strategy: | ||
matrix: | ||
node-version: [20.11.0] | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: pnpm/action-setup@v3 | ||
with: | ||
version: 8 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
cache: 'pnpm' | ||
- id: auth | ||
uses: google-github-actions/auth@v2 | ||
with: | ||
credentials_json: ${{ secrets.SKEET_GCP_SA_KEY }} | ||
- name: Install firebase tools | ||
run: pnpm add -g firebase-tools | ||
- name: GitHub repository setting | ||
run: git config --global url."https://github.com".insteadOf ssh://[email protected] | ||
- name: Install dependencies | ||
run: pnpm install | ||
- name: Build App | ||
run: pnpm -F cloud-task build-doc | ||
env: | ||
NODE_OPTIONS: --max-old-space-size=8192 | ||
- name: Deploy to Firebase | ||
run: firebase deploy --only hosting:skeet-cloud-task |
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
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,74 @@ | ||
import { | ||
VertexAI, | ||
HarmCategory, | ||
HarmBlockThreshold, | ||
GenerationConfig, | ||
Content, | ||
StreamGenerateContentResult, | ||
} from '@google-cloud/vertexai' | ||
import dotenv from 'dotenv' | ||
dotenv.config() | ||
|
||
const project = process.env.GCP_PROJECT_ID || '' | ||
const location = process.env.GCP_LOCATION || '' | ||
|
||
export interface ConfigGeminiType extends GenerationConfig { | ||
model: string | ||
project: string | ||
location: string | ||
} | ||
|
||
export type GeminiModel = 'gemini-1.0-pro' | 'gemini-1.0-pro-vision' | ||
|
||
export const defaultGeminiConfig: ConfigGeminiType = { | ||
project, | ||
location, | ||
max_output_tokens: 256, | ||
temperature: 0.1, | ||
top_p: 1, | ||
top_k: 40, | ||
model: 'gemini-1.0-pro' as GeminiModel, | ||
} | ||
|
||
export const geminiChatStream = async ( | ||
contents: Content[], | ||
config = defaultGeminiConfig, | ||
) => { | ||
try { | ||
if (config.project === '' || config.location === '') { | ||
console.error( | ||
'GCP_PROJECT_ID and GCP_LOCATION are required in .env file.\n\nor you can pass them as arguments to the function.', | ||
) | ||
process.exit(1) | ||
} | ||
const { model, project, location, ...generation_config } = config | ||
const vertex_ai = new VertexAI({ | ||
project, | ||
location, | ||
}) | ||
|
||
// Instantiate models | ||
const generativeModel = vertex_ai.getGenerativeModel({ | ||
model, | ||
safety_settings: [ | ||
{ | ||
category: HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT, | ||
threshold: HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE, | ||
}, | ||
], | ||
generation_config, | ||
}) | ||
|
||
const request = { | ||
contents, | ||
} | ||
|
||
const streamingResp = await generativeModel.generateContentStream(request) | ||
if (streamingResp == null) { | ||
throw new Error('Error in geminiChatStream: No response from Vertex AI') | ||
} | ||
return streamingResp as StreamGenerateContentResult | ||
} catch (error) { | ||
throw new Error(`Error in geminiChat: ${error}`) | ||
} | ||
} |
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.