Skip to content

Commit

Permalink
Add LLM Implementation via xassist
Browse files Browse the repository at this point in the history
  • Loading branch information
tharun571 authored and vgvassilev committed Sep 12, 2024
1 parent 7d20476 commit 02a8ca3
Show file tree
Hide file tree
Showing 11 changed files with 524 additions and 3 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,7 @@ __pycache__/
build/

bld

# LLM Implementation
*_api_key.txt
*_chat_history.txt
41 changes: 40 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,13 @@ set(XEUS_CPP_SRC
src/xutils.cpp
)

if(NOT EMSCRIPTEN)
list(APPEND XEUS_CPP_SRC
src/xmagics/xassist.hpp
src/xmagics/xassist.cpp
)
endif()

if(EMSCRIPTEN)
list(APPEND XEUS_CPP_SRC src/xinterpreter_wasm.cpp)
endif()
Expand Down Expand Up @@ -309,9 +316,41 @@ macro(xeus_cpp_create_target target_name linkage output_name)
else ()
set(XEUS_CPP_XEUS_TARGET xeus-static)
endif ()

#This is a workaround for the issue with the libcurl target on Windows specifically for xassist
if (WIN32)
# Set the MSVC runtime library
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")

# Find libcurl
find_package(CURL REQUIRED)

# Add CURL_STATICLIB definition if linking statically
if (CURL_STATICLIB)
target_compile_definitions(${target_name} PUBLIC CURL_STATICLIB)
endif()

target_link_libraries(${target_name} PUBLIC ${XEUS_CPP_XEUS_TARGET} clangCppInterOp pugixml argparse::argparse)
# Link against the correct libcurl target
if (CURL_FOUND)
target_include_directories(${target_name} PRIVATE ${CURL_INCLUDE_DIRS})
target_link_libraries(${target_name} PRIVATE ${CURL_LIBRARIES})
endif()

# Existing target_link_libraries call, adjusted for clarity
target_link_libraries(${target_name} PUBLIC ${XEUS_CPP_XEUS_TARGET} clangCppInterOp pugixml argparse::argparse)

# Ensure all linked libraries use the same runtime library
if (MSVC)
target_compile_options(${target_name} PRIVATE "/MD$<$<CONFIG:Debug>:d>")
endif()
elseif (NOT EMSCRIPTEN)
# Curl initialised specifically for xassist
target_link_libraries(${target_name} PUBLIC ${XEUS_CPP_XEUS_TARGET} clangCppInterOp pugixml argparse::argparse curl)
else ()
# TODO : Add curl support for emscripten
target_link_libraries(${target_name} PUBLIC ${XEUS_CPP_XEUS_TARGET} clangCppInterOp pugixml argparse::argparse)
endif()

if (WIN32 OR CYGWIN)
#
elseif (APPLE)
Expand Down
Binary file added docs/source/gemini.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ The Xeus-Cpp is a Jupyter kernel for the C++ programming language
InstallationAndUsage
UsingXeus-Cpp
tutorials
magics
dev-build-options
debug
FAQ
Expand Down
41 changes: 41 additions & 0 deletions docs/source/magics.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
Magics commands
--------------------

Magics are special commands for the kernel that are not part of the C++
programming language.

There are defined with the symbol ``%`` for a line magic and ``%%`` for a cell
magic.

Here are the magics available in xeus-cpp.

%%xassist
========================

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.

- Save the api key

.. code::
%%xassist model --save-key
key
- Use the model

.. code::
%%xassist model
prompt
- Reset model and clear chat history

.. code::
%%xassist model --refresh
- Example

.. image:: gemini.png

A new prompt is sent to the model everytime and the functionality to use previous context will be added soon.
2 changes: 1 addition & 1 deletion environment-wasm-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ channels:
dependencies:
- cmake
- emsdk >=3.1.11
- empack >=2.0.1
- empack >=2.0.1
2 changes: 1 addition & 1 deletion environment-wasm-host.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ dependencies:
- xeus
- CppInterOp>=1.3.0
- cpp-argparse
- pugixml
- pugixml
6 changes: 6 additions & 0 deletions src/xinterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
#include "xinput.hpp"
#include "xinspect.hpp"
#include "xmagics/os.hpp"
#ifndef EMSCRIPTEN
#include "xmagics/xassist.hpp"
#endif
#include "xparser.hpp"
#include "xsystem.hpp"

Expand Down Expand Up @@ -404,5 +407,8 @@ __get_cxx_version ()
// preamble_manager["magics"].get_cast<xmagics_manager>().register_magic("file", writefile());
// preamble_manager["magics"].get_cast<xmagics_manager>().register_magic("timeit", timeit(&m_interpreter));
// preamble_manager["magics"].get_cast<xmagics_manager>().register_magic("python", pythonexec());
#ifndef EMSCRIPTEN
preamble_manager["magics"].get_cast<xmagics_manager>().register_magic("xassist", xassist());
#endif
}
}
Loading

0 comments on commit 02a8ca3

Please sign in to comment.