Skip to content

Commit

Permalink
extend DB schema to include gitURL
Browse files Browse the repository at this point in the history
  • Loading branch information
ili16 committed Mar 5, 2024
1 parent af6d695 commit c5b739a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
4 changes: 0 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,6 @@ func main() {
return
}

log.Printf("Decoded Query: %s", decodedQuery)

response, err := weaviate.RetrieveResponseByID(decodedQuery)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
Expand All @@ -128,8 +126,6 @@ func main() {
return
}

log.Printf("Decoded Query: %s", decodedQuery)

response, err := weaviate.RetrieveProperties(decodedQuery)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
Expand Down
11 changes: 10 additions & 1 deletion ollama/ollama.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ func GenerateResponse(prompt map[string]interface{}) (weaviate.ResponseData, err
set = "default"
}

gitURL, ok := prompt["gitURL"].(string)

log.Printf("gitURL: %s\n", gitURL)

if !ok {
gitURL = ""
}

instruct, ok := prompt["instruct"].(string)

log.Printf("ok: %v", ok)
Expand Down Expand Up @@ -92,7 +100,7 @@ func GenerateResponse(prompt map[string]interface{}) (weaviate.ResponseData, err
return weaviate.ResponseData{}, errors.New("invalid response format")
}

PromptID, err := weaviate.CreatePromptObject(instruct, code, "Prompt")
PromptID, err := weaviate.CreatePromptObject(instruct, code, "Prompt", gitURL)
if err != nil {
return weaviate.ResponseData{}, err
}
Expand All @@ -113,6 +121,7 @@ func GenerateResponse(prompt map[string]interface{}) (weaviate.ResponseData, err
Response: response,
PromptID: PromptID,
Instruct: instruct,
GitURL: gitURL,
}

return responseData, nil
Expand Down
15 changes: 14 additions & 1 deletion weaviate/weaviate.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ type ResponseData struct {
Response string `json:"response"`
PromptID string `json:"promptID"`
Instruct string `json:"instruct"`
GitURL string `json:"gitURL"`
}

type PromptProperties struct {
Code string `json:"code"`
HasResponse string `json:"hasResponse"`
Instruct string `json:"instruct"`
Rank int `json:"rank"`
GitURL string `json:"gitURL"`
}

func InitSchema() error {
Expand Down Expand Up @@ -120,6 +122,16 @@ func InitSchema() error {
},
},
},
{
DataType: []string{"text"},
Description: "A link to the git blob containing the code with the line and character position of the prompt",
Name: "gitURL",
ModuleConfig: map[string]interface{}{
"text2vec-transformers": map[string]interface{}{
"skip": true,
},
},
},
},
}

Expand Down Expand Up @@ -158,7 +170,7 @@ func createClass(className, description, vectorizer string, properties []*models
return nil
}

func CreatePromptObject(instruct string, code string, class string) (string, error) {
func CreatePromptObject(instruct string, code string, class string, gitURL string) (string, error) {
client, err := loadClient()
if err != nil {
return "", err
Expand All @@ -168,6 +180,7 @@ func CreatePromptObject(instruct string, code string, class string) (string, err
"instruct": instruct,
"code": code,
"rank": 1,
"gitURL": gitURL,
}

weaviateObject, err := client.Data().Creator().
Expand Down
2 changes: 2 additions & 0 deletions weaviate/weaviate_retrieval.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func RetrieveProperties(id string) (PromptProperties, error) {
HasResponse []map[string]interface{} `json:"hasResponse"`
Instruct string `json:"instruct"`
Rank int `json:"rank"`
GitURL string `json:"gitURL"`
}

if err := json.Unmarshal(propertiesJSON, &temp); err != nil {
Expand Down Expand Up @@ -70,6 +71,7 @@ func RetrieveProperties(id string) (PromptProperties, error) {
HasResponse: responseText,
Instruct: temp.Instruct,
Rank: temp.Rank,
GitURL: temp.GitURL,
}

return promptProperties, nil
Expand Down

0 comments on commit c5b739a

Please sign in to comment.