Skip to content

Commit 89e1f7c

Browse files
committed
Add LLM Implementation via xassist
1 parent 7d20476 commit 89e1f7c

11 files changed

+524
-3
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,7 @@ __pycache__/
3838
build/
3939

4040
bld
41+
42+
# LLM Implementation
43+
*_api_key.txt
44+
*_chat_history.txt

CMakeLists.txt

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,13 @@ set(XEUS_CPP_SRC
205205
src/xutils.cpp
206206
)
207207

208+
if(NOT EMSCRIPTEN)
209+
list(APPEND XEUS_CPP_SRC
210+
src/xmagics/xassist.hpp
211+
src/xmagics/xassist.cpp
212+
)
213+
endif()
214+
208215
if(EMSCRIPTEN)
209216
list(APPEND XEUS_CPP_SRC src/xinterpreter_wasm.cpp)
210217
endif()
@@ -309,9 +316,41 @@ macro(xeus_cpp_create_target target_name linkage output_name)
309316
else ()
310317
set(XEUS_CPP_XEUS_TARGET xeus-static)
311318
endif ()
319+
320+
#This is a workaround for the issue with the libcurl target on Windows specifically for xassist
321+
if (WIN32)
322+
# Set the MSVC runtime library
323+
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
324+
325+
# Find libcurl
326+
find_package(CURL REQUIRED)
327+
328+
# Add CURL_STATICLIB definition if linking statically
329+
if (CURL_STATICLIB)
330+
target_compile_definitions(${target_name} PUBLIC CURL_STATICLIB)
331+
endif()
312332

313-
target_link_libraries(${target_name} PUBLIC ${XEUS_CPP_XEUS_TARGET} clangCppInterOp pugixml argparse::argparse)
333+
# Link against the correct libcurl target
334+
if (CURL_FOUND)
335+
target_include_directories(${target_name} PRIVATE ${CURL_INCLUDE_DIRS})
336+
target_link_libraries(${target_name} PRIVATE ${CURL_LIBRARIES})
337+
endif()
314338

339+
# Existing target_link_libraries call, adjusted for clarity
340+
target_link_libraries(${target_name} PUBLIC ${XEUS_CPP_XEUS_TARGET} clangCppInterOp pugixml argparse::argparse)
341+
342+
# Ensure all linked libraries use the same runtime library
343+
if (MSVC)
344+
target_compile_options(${target_name} PRIVATE "/MD$<$<CONFIG:Debug>:d>")
345+
endif()
346+
elseif (NOT EMSCRIPTEN)
347+
# Curl initialised specifically for xassist
348+
target_link_libraries(${target_name} PUBLIC ${XEUS_CPP_XEUS_TARGET} clangCppInterOp pugixml argparse::argparse curl)
349+
else ()
350+
# TODO : Add curl support for emscripten
351+
target_link_libraries(${target_name} PUBLIC ${XEUS_CPP_XEUS_TARGET} clangCppInterOp pugixml argparse::argparse)
352+
endif()
353+
315354
if (WIN32 OR CYGWIN)
316355
#
317356
elseif (APPLE)

docs/source/gemini.png

6.44 KB
Loading

docs/source/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ The Xeus-Cpp is a Jupyter kernel for the C++ programming language
3434
InstallationAndUsage
3535
UsingXeus-Cpp
3636
tutorials
37+
magics
3738
dev-build-options
3839
debug
3940
FAQ

docs/source/magics.rst

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
Magics commands
2+
--------------------
3+
4+
Magics are special commands for the kernel that are not part of the C++
5+
programming language.
6+
7+
There are defined with the symbol ``%`` for a line magic and ``%%`` for a cell
8+
magic.
9+
10+
Here are the magics available in xeus-cpp.
11+
12+
%%xassist
13+
========================
14+
15+
Leverage the large language models to assist in your development process. Currently supported models are Gemini - gemini-1.5-flash, OpenAI - gpt-3.5-turbo-16k.
16+
17+
- Save the api key
18+
19+
.. code::
20+
21+
%%xassist model --save-key
22+
key
23+
24+
- Use the model
25+
26+
.. code::
27+
28+
%%xassist model
29+
prompt
30+
31+
- Reset model and clear chat history
32+
33+
.. code::
34+
35+
%%xassist model --refresh
36+
37+
- Example
38+
39+
.. image:: gemini.png
40+
41+
A new prompt is sent to the model everytime and the functionality to use previous context will be added soon.

environment-wasm-build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ channels:
44
dependencies:
55
- cmake
66
- emsdk >=3.1.11
7-
- empack >=2.0.1
7+
- empack >=2.0.1

environment-wasm-host.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ dependencies:
88
- xeus
99
- CppInterOp>=1.3.0
1010
- cpp-argparse
11-
- pugixml
11+
- pugixml

src/xinterpreter.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
#include "xinput.hpp"
2929
#include "xinspect.hpp"
3030
#include "xmagics/os.hpp"
31+
#ifndef EMSCRIPTEN
32+
#include "xmagics/xassist.hpp"
33+
#endif
3134
#include "xparser.hpp"
3235
#include "xsystem.hpp"
3336

@@ -404,5 +407,8 @@ __get_cxx_version ()
404407
// preamble_manager["magics"].get_cast<xmagics_manager>().register_magic("file", writefile());
405408
// preamble_manager["magics"].get_cast<xmagics_manager>().register_magic("timeit", timeit(&m_interpreter));
406409
// preamble_manager["magics"].get_cast<xmagics_manager>().register_magic("python", pythonexec());
410+
#ifndef EMSCRIPTEN
411+
preamble_manager["magics"].get_cast<xmagics_manager>().register_magic("xassist", xassist());
412+
#endif
407413
}
408414
}

0 commit comments

Comments
 (0)