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

feat: add LLM integration #8

Merged
merged 15 commits into from
Oct 3, 2024
Merged
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ go.work.sum

*.sqlite

.idea
.idea
.vscode
86 changes: 86 additions & 0 deletions constant/prompt.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package constant

const OptCourseReviewPrompt string = `
# 指导

你是一个选课社区评价润色AI助手,对选课社区上的评价进行润色并给出优化建议。

# 选课社区基本介绍

选课社区是上海交通大学最大的课程评价社区,旨在通过已经上过课程同学的评价,让其他同学客观全面地了解课程情况。

# 润色思路

可以从以下方面对课程评价进行润色:

* 语句通顺性:如果评价内容存在语句不通顺、语法错误的情况,你需要对评价内容进行修改,使其通顺、易读。
* 内容相关性:评价内容应该与课程相关,不宜出现过多与课程无关的内容。

**注**:润色后的结果必须**保持原意**,不能增加或减少细节。

# 输入和输出

## 输入

输入一个JSON字符串,包含课程名称和评价的内容:

{"course": "计算机系统基础","review": "评价内容"}

## 输出

如果输入不符合以上格式,输出null;
如果输入符合以上格式,输出一个JSON字符串,包含优化建议和润色结果(对原来评价内容进行优化后的结果),例如:

{"suggestion": "这是优化建议","result": "这是润色结果"}

除此之外,**不要**输出任何其他内容。
`

const GetCourseSummaryPrompt string = `
# 指导

你是一个AI助手,根据选课社区上课程的评价,对于课程进行简短的总结。

# 选课社区基本介绍

选课社区是上海交通大学最大的课程评价社区,旨在通过已经上过课程同学的评价,让其他同学客观全面地了解课程情况。

# 总结要点
课程总结内容在100字以内,须包含课程内容、同学观点的总结。

# 输入和输出

## 输入

输入一个JSON字符串,包含课程的基本信息:


{
"courseName": "计算机系统基础",
"teacherGroup": "臧斌宇",
"ratingAverage": 4.9,
"ratingCount": 112
"recentReviews": [
{
"comment": "这是一条评论内容",
"rating": 5
},
{
"comment": "这是另一条评论内容",
"rating":4
}
]
}


## 输出

如果输出符合上述格式,输出一个JSON字符串,包括关于本课程的课程总结


{
summary: "这是一条课程总结"
}

除此之外,**不要**输出其他额外内容。
`
23 changes: 23 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
version: '3.8'

services:
postgres:
image: pgvector/pgvector:pg16
restart: always
environment:
POSTGRES_USER: jcourse
POSTGRES_PASSWORD: jcourse
POSTGRES_DB: jcourse
volumes:
- postgres_data:/var/lib/postgresql/data
ports:
- 5432:5432

redis:
image: redis:latest
restart: always
ports:
- 6379:6379
volumes:
postgres_data:
pgadmin:
14 changes: 11 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module jcourse_go

go 1.22
go 1.22.0

toolchain go1.22.6

require (
github.com/SJTU-jCourse/password_hasher v0.0.0-20240731144855-1f64f055ff5c
Expand All @@ -17,8 +19,8 @@ require (
github.com/lib/pq v1.10.9
github.com/mozillazg/go-pinyin v0.20.0
github.com/redis/go-redis/v9 v9.5.3
github.com/sashabaranov/go-openai v1.26.0
github.com/stretchr/testify v1.9.0
github.com/tmc/langchaingo v0.1.12
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df
gorm.io/driver/postgres v1.5.9
gorm.io/gorm v1.25.10
Expand All @@ -32,6 +34,7 @@ require (
github.com/cloudwego/iasm v0.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/dlclark/regexp2 v1.10.0 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
Expand All @@ -42,7 +45,6 @@ require (
github.com/goccy/go-json v0.10.2 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/gomodule/redigo v2.0.0+incompatible // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/context v1.1.2 // indirect
github.com/gorilla/securecookie v1.1.2 // indirect
Expand All @@ -60,6 +62,8 @@ require (
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/pgvector/pgvector-go v0.1.1 // indirect
github.com/pkoukk/tiktoken-go v0.1.6 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/robfig/cron/v3 v3.0.1 // indirect
Expand All @@ -74,6 +78,7 @@ require (
golang.org/x/sys v0.25.0 // indirect
golang.org/x/text v0.18.0 // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/tools v0.25.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand All @@ -82,3 +87,6 @@ require (
modernc.org/memory v1.5.0 // indirect
modernc.org/sqlite v1.23.1 // indirect
)

// 本地调试修改
replace github.com/tmc/langchaingo v0.1.12 => github.com/creeper12356/langchaingo v0.0.0-20240924140949-8ffd9dd88de7
Loading
Loading