🔊 More log after generation
This commit is contained in:
		| @@ -2,7 +2,7 @@ package grpc | |||||||
|  |  | ||||||
| import ( | import ( | ||||||
| 	"context" | 	"context" | ||||||
| 	"fmt" |  | ||||||
| 	"git.solsynth.dev/hypernet/insight/pkg/internal/services" | 	"git.solsynth.dev/hypernet/insight/pkg/internal/services" | ||||||
| 	"git.solsynth.dev/hypernet/insight/pkg/proto" | 	"git.solsynth.dev/hypernet/insight/pkg/proto" | ||||||
| 	"google.golang.org/grpc/codes" | 	"google.golang.org/grpc/codes" | ||||||
| @@ -12,13 +12,13 @@ import ( | |||||||
| func (v *Server) GenerateInsight(ctx context.Context, request *proto.InsightRequest) (*proto.InsightResponse, error) { | func (v *Server) GenerateInsight(ctx context.Context, request *proto.InsightRequest) (*proto.InsightResponse, error) { | ||||||
| 	input := request.GetSource() | 	input := request.GetSource() | ||||||
| 	if err := services.PlaceOrder(uint(request.GetUserId()), len(input)); err != nil { | 	if err := services.PlaceOrder(uint(request.GetUserId()), len(input)); err != nil { | ||||||
| 		return nil, status.Errorf(codes.ResourceExhausted, fmt.Sprintf("failed to place order: %v", err)) | 		return nil, status.Errorf(codes.ResourceExhausted, "failed to place order: %v", err) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	out, err := services.GenerateInsights(input) | 	out, err := services.GenerateInsights(input) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		_ = services.MakeRefund(uint(request.GetUserId()), len(input)) | 		_ = services.MakeRefund(uint(request.GetUserId()), len(input)) | ||||||
| 		return nil, status.Errorf(codes.Internal, fmt.Sprintf("failed to generate insight: %v", err)) | 		return nil, status.Errorf(codes.Internal, "failed to generate insight: %v", err) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	return &proto.InsightResponse{Response: out}, nil | 	return &proto.InsightResponse{Response: out}, nil | ||||||
|   | |||||||
| @@ -6,6 +6,7 @@ import ( | |||||||
| 	"net/http" | 	"net/http" | ||||||
| 	"time" | 	"time" | ||||||
|  |  | ||||||
|  | 	"github.com/rs/zerolog/log" | ||||||
| 	"github.com/spf13/viper" | 	"github.com/spf13/viper" | ||||||
| 	"github.com/tmc/langchaingo/llms" | 	"github.com/tmc/langchaingo/llms" | ||||||
| 	"github.com/tmc/langchaingo/llms/ollama" | 	"github.com/tmc/langchaingo/llms/ollama" | ||||||
| @@ -49,11 +50,13 @@ func GenerateInsights(source string) (string, error) { | |||||||
| 		return "", fmt.Errorf("failed to format prompt: %v", err) | 		return "", fmt.Errorf("failed to format prompt: %v", err) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	ctx, cancel := context.WithTimeout(context.Background(), 3*time.Minute) | 	start := time.Now() | ||||||
| 	defer cancel() | 	completion, err := LargeModel.Call(context.Background(), inPrompt, | ||||||
| 	completion, err := LargeModel.Call(ctx, inPrompt, |  | ||||||
| 		llms.WithTemperature(0.8), | 		llms.WithTemperature(0.8), | ||||||
| 	) | 	) | ||||||
|  | 	took := time.Since(start) | ||||||
|  |  | ||||||
|  | 	log.Info().Dur("took", took).Msg("Insight generated successfully...") | ||||||
|  |  | ||||||
| 	return completion, err | 	return completion, err | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user