tools.go

 1package tools
 2
 3import (
 4	"context"
 5)
 6
 7type (
 8	sessionIDContextKey string
 9	messageIDContextKey string
10	supportsImagesKey   string
11	modelNameKey        string
12)
13
14const (
15	// SessionIDContextKey is the key for the session ID in the context.
16	SessionIDContextKey sessionIDContextKey = "session_id"
17	// MessageIDContextKey is the key for the message ID in the context.
18	MessageIDContextKey messageIDContextKey = "message_id"
19	// SupportsImagesContextKey is the key for the model's image support capability.
20	SupportsImagesContextKey supportsImagesKey = "supports_images"
21	// ModelNameContextKey is the key for the model name in the context.
22	ModelNameContextKey modelNameKey = "model_name"
23)
24
25// GetSessionFromContext retrieves the session ID from the context.
26func GetSessionFromContext(ctx context.Context) string {
27	sessionID := ctx.Value(SessionIDContextKey)
28	if sessionID == nil {
29		return ""
30	}
31	s, ok := sessionID.(string)
32	if !ok {
33		return ""
34	}
35	return s
36}
37
38// GetMessageFromContext retrieves the message ID from the context.
39func GetMessageFromContext(ctx context.Context) string {
40	messageID := ctx.Value(MessageIDContextKey)
41	if messageID == nil {
42		return ""
43	}
44	s, ok := messageID.(string)
45	if !ok {
46		return ""
47	}
48	return s
49}
50
51// GetSupportsImagesFromContext retrieves whether the model supports images from the context.
52func GetSupportsImagesFromContext(ctx context.Context) bool {
53	supportsImages := ctx.Value(SupportsImagesContextKey)
54	if supportsImages == nil {
55		return false
56	}
57	if supports, ok := supportsImages.(bool); ok {
58		return supports
59	}
60	return false
61}
62
63// GetModelNameFromContext retrieves the model name from the context.
64func GetModelNameFromContext(ctx context.Context) string {
65	modelName := ctx.Value(ModelNameContextKey)
66	if modelName == nil {
67		return ""
68	}
69	s, ok := modelName.(string)
70	if !ok {
71		return ""
72	}
73	return s
74}