-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(llm): complete comments in 'service/llm.go'
- Loading branch information
1 parent
c345dae
commit 0d3f77b
Showing
3 changed files
with
26 additions
and
4 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
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 |
---|---|---|
|
@@ -19,6 +19,12 @@ import ( | |
"github.com/tmc/langchaingo/vectorstores" | ||
Check failure on line 19 in service/llm.go GitHub Actions / build
|
||
) | ||
|
||
// OptCourseReview使用LLM提示词对课程评价内容进行优化。 | ||
// courseName为课程名称, | ||
// reviewContent为评价的内容, | ||
// 函数返回值包含两个字段: | ||
// Suggestion为修改建议, | ||
// Result为根据修改建议给出的一种修改结果。 | ||
func OptCourseReview(courseName string, reviewContent string) (dto.OptCourseReviewResponse, error) { | ||
llm, err := openai.New() | ||
if err != nil { | ||
|
@@ -50,6 +56,11 @@ func OptCourseReview(courseName string, reviewContent string) (dto.OptCourseRevi | |
return response, err | ||
} | ||
|
||
// GetCourseSummary使用LLM提示词基于课程评价生成课程总结。 | ||
// courseID为课程的ID, | ||
// 返回值包含课程的总结。 | ||
// TODO: 此处基于课程最近的100条评价内容生成课程总结,后续可 | ||
// 以进一步调整和优化。 | ||
func GetCourseSummary(ctx context.Context, courseID int64) (*dto.GetCourseSummaryResponse, error) { | ||
courseQuery := repository.NewCourseQuery(dal.GetDBClient()) | ||
coursePOs, err := courseQuery.GetCourse(ctx, repository.WithID(courseID)) | ||
|
@@ -118,7 +129,12 @@ func GetCourseSummary(ctx context.Context, courseID int64) (*dto.GetCourseSummar | |
|
||
} | ||
|
||
func VectorizeCourseReviews(ctx context.Context, courseID int64) error { | ||
// VectorizeCourse对课程进行向量化, | ||
// 用于后续GetMatchCourses进行向量匹配。 | ||
// courseID为课程ID。 | ||
// TODO: 此处使用课程最近100条评论和课程名进行向量化,后续可以 | ||
// 优化和调整; | ||
func VectorizeCourse(ctx context.Context, courseID int64) error { | ||
courseQuery := repository.NewCourseQuery(dal.GetDBClient()) | ||
coursePOs, err := courseQuery.GetCourse(ctx, repository.WithID(courseID)) | ||
if err != nil || len(coursePOs) == 0 { | ||
|
@@ -176,6 +192,12 @@ func VectorizeCourseReviews(ctx context.Context, courseID int64) error { | |
return err | ||
} | ||
|
||
// GetMatchCourses使用向量匹配, | ||
// 根据自然语言描述找到最匹配的课程列表。 | ||
// description为用户提供的自然语言描述。 | ||
// TODO: 此处向量相似性计算(SimilaritySearch)中, | ||
// 输出的课程列表数量为2,后续可以修改。 | ||
|
||
func GetMatchCourses(ctx context.Context, description string) ([]model.CourseSummary, error) { | ||
vectorStore, err := rpc.OpenVectorStoreConn() | ||
|
||
|