-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implement CLOVA Studio integration for drawing word generation (#…
…121) * feat: Install axios for HTTP requests * feat: Implement CLOVA Studio integration for drawing word generation * chore: Add CLOVA API keys to CI/CD workflow --------- Co-authored-by: 유미라 <[email protected]>
- Loading branch information
Showing
8 changed files
with
135 additions
and
9 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 |
---|---|---|
|
@@ -31,6 +31,8 @@ jobs: | |
run: | | ||
echo "REDIS_HOST=${{ secrets.REDIS_HOST }}" >> .env | ||
echo "REDIS_PORT=${{ secrets.REDIS_PORT }}" >> .env | ||
echo "CLOVA_API_KEY=${{ secrets.CLOVA_API_KEY }}" >> .env | ||
echo "CLOVA_GATEWAY_KEY=${{ secrets.CLOVA_GATEWAY_KEY }}" >> .env | ||
- name: Run tests | ||
run: pnpm --filter server test | true | ||
|
@@ -62,6 +64,8 @@ jobs: | |
build-args: | | ||
REDIS_HOST=${{ secrets.REDIS_HOST }} | ||
REDIS_PORT=${{ secrets.REDIS_PORT }} | ||
CLOVA_API_KEY=${{ secrets.CLOVA_API_KEY }} | ||
CLOVA_GATEWAY_KEY=${{ secrets.CLOVA_GATEWAY_KEY }} | ||
- name: Deploy to Server | ||
uses: appleboy/[email protected] | ||
|
@@ -77,4 +81,4 @@ jobs: | |
docker stop troublepainter || true | ||
docker rm troublepainter || true | ||
docker run -d --name troublepainter -p 3000:3000 -e REDIS_HOST=${{ secrets.REDIS_HOST }} -e REDIS_PORT=${{ secrets.REDIS_PORT }} --restart unless-stopped ${{ secrets.DOCKERHUB_USERNAME }}/troublepainter:latest | ||
docker run -d --name troublepainter -p 3000:3000 -e REDIS_HOST=${{ secrets.REDIS_HOST }} -e REDIS_PORT=${{ secrets.REDIS_PORT }} -e CLOVA_API_KEY=${{ secrets.CLOVA_API_KEY }} -e CLOVA_GATEWAY_KEY=${{ secrets.CLOVA_GATEWAY_KEY }} --restart unless-stopped ${{ secrets.DOCKERHUB_USERNAME }}/troublepainter:latest |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,60 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { ConfigService } from '@nestjs/config'; | ||
import axios, { AxiosInstance } from 'axios'; | ||
import { Difficulty } from './enums/game.status.enum'; | ||
|
||
@Injectable() | ||
export class ClovaClient { | ||
private readonly client: AxiosInstance; | ||
|
||
constructor(private configService: ConfigService) { | ||
const apiKey = this.configService.get<string>('CLOVA_API_KEY'); | ||
const gatewayKey = this.configService.get<string>('CLOVA_GATEWAY_KEY'); | ||
|
||
this.client = axios.create({ | ||
baseURL: 'https://clovastudio.stream.ntruss.com/testapp/v1', | ||
headers: { | ||
'X-NCP-CLOVASTUDIO-API-KEY': apiKey, | ||
'X-NCP-APIGW-API-KEY': gatewayKey, | ||
}, | ||
}); | ||
} | ||
async getDrawingWords(difficulty: Difficulty, count: number) { | ||
const request = { | ||
messages: [ | ||
{ | ||
role: 'system', | ||
content: '', | ||
}, | ||
{ | ||
role: 'user', | ||
content: `당신은 드로잉 게임의 출제자입니다. ${difficulty}난이도의 명사 ${count}개를 제시해주세요. | ||
- 30초 안에 그릴 수 있는 단어만 선택 | ||
- 단어만 나열 (1. 2. 3. 형식) | ||
- 설명이나 부연설명 없이 단어만 작성 | ||
`, | ||
}, | ||
], | ||
topP: 0.8, | ||
topK: 0, | ||
maxTokens: 256, | ||
temperature: 0.8, | ||
repeatPenalty: 5.0, | ||
stopBefore: [], | ||
includeAiFilters: true, | ||
seed: Math.floor(Math.random() * 1000000), | ||
}; | ||
|
||
try { | ||
const response = await this.client.post('/chat-completions/HCX-003', request); | ||
const result = response.data.result.message.content | ||
.split('\n') | ||
.map((line: string) => line.trim()) | ||
.filter((line: string) => line) | ||
.map((line: string) => line.replace(/^\d+\.\s*/, '')); | ||
return result; | ||
} catch (error) { | ||
throw new Error(`CLOVA API request failed: ${error.message}`); | ||
} | ||
} | ||
} |
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