forked from sigoden/aichat
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.scm
More file actions
executable file
·135 lines (102 loc) · 5.15 KB
/
Copy pathexample.scm
File metadata and controls
executable file
·135 lines (102 loc) · 5.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/usr/bin/env guile
!#
;;
;; example.scm - Example usage of CAIChat OpenCog module
;;
;; Add current directory to load path
(add-to-load-path ".")
;; Load the CAIChat modules
(use-modules (opencog caichat config)
(opencog caichat)
(opencog caichat rag)
(opencog caichat repl))
(display "╔══════════════════════════════════════════════════════════════╗\n")
(display "║ CAIChat OpenCog Example ║\n")
(display "╚══════════════════════════════════════════════════════════════╝\n\n")
;; Example 1: Basic configuration (without real API keys)
(display "Example 1: Configuration\n")
(display "========================\n")
;; Show how to configure providers (with dummy keys for example)
(display "Setting up OpenAI configuration (example):\n")
(display " (caichat-setup-openai \"your-api-key-here\")\n\n")
(display "Setting up Claude configuration (example):\n")
(display " (caichat-setup-claude \"your-api-key-here\")\n\n")
(display "Setting up Ollama configuration (example):\n")
(display " (caichat-setup-ollama \"http://localhost:11434\")\n\n")
;; Example 2: Document RAG
(display "Example 2: Document RAG\n")
(display "=======================\n")
;; Create a sample knowledge base
(caichat-create-knowledge-base "opencog-docs" "OpenCog documentation")
;; Add some sample documents
(caichat-add-document "opencog-intro"
"OpenCog is a cognitive architecture project aimed at creating beneficial artificial general intelligence. It combines symbolic and subsymbolic AI approaches."
'(("source" . "opencog-intro.txt")
("type" . "documentation")))
(caichat-add-document "atomspace-intro"
"The AtomSpace is OpenCog's knowledge representation system. It stores knowledge as a hypergraph of typed nodes and links called atoms."
'(("source" . "atomspace-intro.txt")
("type" . "documentation")))
(display "✓ Added sample documents to knowledge base\n")
;; Demonstrate search
(let ((search-results (caichat-search-documents "What is AtomSpace?" 2)))
(display (format #f "✓ Search results for 'What is AtomSpace?': ~a matches\n"
(length search-results)))
(for-each
(lambda (result)
(display (format #f " - Document: ~a (similarity: ~a)\n"
(car result) (cadr result))))
search-results))
(display "\n")
;; Example 3: Embedding similarity
(display "Example 3: Text Embeddings\n")
(display "==========================\n")
(let ((text1 "artificial intelligence")
(text2 "machine learning")
(text3 "cooking recipes"))
(let ((emb1 (caichat-embed-text text1))
(emb2 (caichat-embed-text text2))
(emb3 (caichat-embed-text text3)))
(display (format #f "Text 1: '~a' -> ~a\n" text1 emb1))
(display (format #f "Text 2: '~a' -> ~a\n" text2 emb2))
(display (format #f "Text 3: '~a' -> ~a\n" text3 emb3))
(let ((sim12 (calculate-cosine-similarity emb1 emb2))
(sim13 (calculate-cosine-similarity emb1 emb3)))
(display (format #f "Similarity between 1&2: ~a\n" sim12))
(display (format #f "Similarity between 1&3: ~a\n" sim13))
(display (format #f "Expected: 1&2 should be more similar than 1&3\n")))))
(display "\n")
;; Example 4: Configuration management
(display "Example 4: Configuration Management\n")
(display "===================================\n")
(display "Available providers: ")
(let ((providers (caichat-list-providers)))
(display (if (null? providers) "None configured" providers)))
(display "\n")
(display "Default provider: ")
(let ((default (caichat-get-default-provider)))
(display default))
(display "\n\n")
;; Example 5: Conversation simulation (without actual API calls)
(display "Example 5: Conversation Structure\n")
(display "=================================\n")
(display "This is how you would use CAIChat for conversations:\n\n")
(display "1. Configure a provider:\n")
(display " (caichat-setup-openai \"your-api-key\")\n\n")
(display "2. Start a session:\n")
(display " (define session (caichat-start-session \"openai\" \"gpt-3.5-turbo\"))\n\n")
(display "3. Chat:\n")
(display " (caichat-chat session \"Hello, how are you?\")\n\n")
(display "4. Ask questions about atoms:\n")
(display " (define my-atom (Concept \"artificial-intelligence\"))\n")
(display " (caichat-ask-about-atom my-atom \"What are the applications?\")\n\n")
(display "5. Use RAG:\n")
(display " (caichat-rag-query \"What is OpenCog?\" \"openai\" \"gpt-4\" 3)\n\n")
(display "6. Start interactive REPL:\n")
(display " (caichat-repl)\n\n")
(display "Example complete! 🎉\n")
(display "\nTo actually use CAIChat with real LLMs:\n")
(display "1. Install OpenCog and required dependencies\n")
(display "2. Build the C++ components with CMake\n")
(display "3. Set up your API keys\n")
(display "4. Start using the functions above!\n")