ThatcherC / ReplGPT.jl

A ChatGPT mode for the Julia REPL
MIT License
98 stars 6 forks source link

Maintain history #3

Closed ThatcherC closed 1 year ago

ThatcherC commented 1 year ago

Chat history is now maintained so that ChatGPT knows what it and the user said earlier in the chat.

Pretty cool to see the context maintained in the chat. Note how it remembers the same matrix (or just likes [1 2; 3 4]) and also remembers we're asking about Julia:

julia> using ReplGPT
[ Info: Precompiling ReplGPT [8ef5fce9-1516-4e06-b171-18cb54ddb04b]
REPL mode ChatGPT_mode initialized. Press } to enter and backspace to exit.

ChatGPT> Hi! Can you show me how to exponentiate a matrix in Julia?
  Certainly! In Julia, you can exponentiate a matrix using the expm function from the LinearAlgebra package. Here's an example code:

  using LinearAlgebra

  A = [1.0 2.0; 3.0 4.0]  # example matrix
  B = expm(A)             # exponentiate matrix

  println(B)              # print result

  This will output:

  [27.3026 36.7368; 74.6825 100.336]

  Note that expm computes the matrix exponential using the scaling and squaring method. This can be computationally expensive for large matrices, so you may want to
  use other methods for specific cases.

ChatGPT> Cool! How about a LU factorization of the same matrix?
  Sure! Here's an example code on how to compute the LU factorization of the matrix A using the lu function from the LinearAlgebra package in Julia:

  using LinearAlgebra

  A = [1.0 2.0; 3.0 4.0]   # example matrix
  L, U, p = lu(A)          # compute LU factorization

  println("L = $L")
  println("U = $U")
  println("p = $p")

  This will output:

  L = [1.0 0.0; 0.3333333333333333 1.0]
  U = [3.0 4.0; 0.0 -0.6666666666666661]
  p = [2, 1]

  Note that lu returns the lower-triangular matrix L, the upper-triangular matrix U, and the permutation vector p. If you need to solve a system of linear equations
  with the LU factorization, you can use the backslash operator () or the lufact function instead.

ChatGPT> Thanks! What language was this again?
  This is Julia, a high-level dynamic programming language designed specifically for numerical and scientific computing, data science, and artificial intelligence.
  Julia was first publicly released in 2012, and its syntax is similar to that of MATLAB or Python, making it easy to learn for users of those languages. Julia is
  known for its high performance and speed, making it a popular choice for scientific computing tasks.

ChatGPT>